public class Equ extends Object
You can also register your own functions and operators by calling the static methods registerFunction and registerOperator. These add to a static Map so there are then available for the duration of your application.
A support instance can be handed to an instance of Equ with the setSupport() method. This must be done prior to calling evaluate. When a variable is found in the equation (i.e.: not a known function, like x or myvar) then the support instance is asked to instantiate the variable. It is expected that it will do what is necessary to come up with it. The test cases show a support instance that maintains a local Map of variable name / value pairs. But a database could be used as well, for instance.
Modifier | Constructor and Description |
---|---|
protected |
Equ() |
Modifier and Type | Method and Description |
---|---|
Set<String> |
compile(String _equ) |
Object |
evaluate() |
Object |
evaluate(String _equ) |
Function |
function(TokVariable varTok) |
static Set<String> |
gatherVariables(List<EquPart> tokens) |
Date |
getBaseDate() |
static Equ |
getInstance() |
static Equ |
getInstance(boolean fresh) |
org.apache.commons.codec.language.Metaphone |
getMetaphone() |
EquationSupport |
getSupport() |
protected void |
initialize() |
protected void |
initializeSupport() |
protected List<EquPart> |
multiplize(List<EquPart> oldTokens) |
protected List<EquPart> |
negatize(List<EquPart> equParts)
change subtractions to negations if necessary
|
Operator |
operator(Token tok) |
void |
registerFunction(String name,
Class<?> functionSubclass) |
void |
registerOperator(String name,
Class<?> operatorSubclass) |
protected List<EquPart> |
rpnize(List<EquPart> oldTokens)
Create a reverse Polish notation form of the equation
|
void |
setBaseDate(Date newBaseDate) |
void |
setSupport(EquationSupport newSupport) |
String |
showRPN() |
void |
showRPN(StringBuilder sb) |
protected List<EquPart> |
tokenize() |
String |
toString() |
void |
unregisterFunction(String name) |
void |
unregisterOperator(String name) |
public static Equ getInstance()
public static Equ getInstance(boolean fresh)
public Object evaluate()
public Function function(TokVariable varTok)
public Date getBaseDate()
public org.apache.commons.codec.language.Metaphone getMetaphone()
public EquationSupport getSupport()
protected void initialize()
protected void initializeSupport()
protected List<EquPart> negatize(List<EquPart> equParts)
protected List<EquPart> rpnize(List<EquPart> oldTokens)
public void setBaseDate(Date newBaseDate)
public void setSupport(EquationSupport newSupport)
public String showRPN()
public void showRPN(StringBuilder sb)
public void unregisterFunction(String name)
public void unregisterOperator(String name)
Copyright © 2018 CodeTaco. All rights reserved.