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) |
com.codetaco.math.impl.Function |
function(com.codetaco.math.impl.token.TokVariable varTok) |
static Set<String> |
gatherVariables(List<com.codetaco.math.impl.EquPart> tokens) |
Date |
getBaseDate() |
static Equ |
getInstance() |
static Equ |
getInstance(boolean fresh) |
static Equ |
getInstance(com.codetaco.math.impl.support.EquationSupport support) |
org.apache.commons.codec.language.Metaphone |
getMetaphone() |
com.codetaco.math.impl.support.EquationSupport |
getSupport() |
protected void |
initialize() |
protected void |
initializeSupport() |
protected List<com.codetaco.math.impl.EquPart> |
multiplize(List<com.codetaco.math.impl.EquPart> oldTokens) |
protected List<com.codetaco.math.impl.EquPart> |
negatize(List<com.codetaco.math.impl.EquPart> equParts)
change subtractions to negations if necessary
|
com.codetaco.math.impl.Operator |
operator(com.codetaco.math.impl.token.Token tok) |
void |
registerFunction(String name,
Class<?> functionSubclass) |
void |
registerOperator(String name,
Class<?> operatorSubclass) |
protected List<com.codetaco.math.impl.EquPart> |
rpnize(List<com.codetaco.math.impl.EquPart> oldTokens)
Create a reverse Polish notation form of the equation
|
void |
setBaseDate(Date newBaseDate) |
Equ |
setSupport(com.codetaco.math.impl.support.EquationSupport newSupport) |
String |
showRPN() |
void |
showRPN(StringBuilder sb) |
protected List<com.codetaco.math.impl.EquPart> |
tokenize() |
String |
toString() |
void |
unregisterFunction(String name) |
void |
unregisterOperator(String name) |
public static Set<String> gatherVariables(List<com.codetaco.math.impl.EquPart> tokens)
public static Equ getInstance(com.codetaco.math.impl.support.EquationSupport support)
public static Equ getInstance()
public static Equ getInstance(boolean fresh)
public Object evaluate()
public com.codetaco.math.impl.Function function(com.codetaco.math.impl.token.TokVariable varTok)
public Date getBaseDate()
public org.apache.commons.codec.language.Metaphone getMetaphone()
public com.codetaco.math.impl.support.EquationSupport getSupport()
protected void initialize()
protected void initializeSupport()
protected List<com.codetaco.math.impl.EquPart> multiplize(List<com.codetaco.math.impl.EquPart> oldTokens)
protected List<com.codetaco.math.impl.EquPart> negatize(List<com.codetaco.math.impl.EquPart> equParts)
public com.codetaco.math.impl.Operator operator(com.codetaco.math.impl.token.Token tok)
protected List<com.codetaco.math.impl.EquPart> rpnize(List<com.codetaco.math.impl.EquPart> oldTokens)
public void setBaseDate(Date newBaseDate)
public Equ setSupport(com.codetaco.math.impl.support.EquationSupport newSupport)
public String showRPN()
public void showRPN(StringBuilder sb)
protected List<com.codetaco.math.impl.EquPart> tokenize()
public void unregisterFunction(String name)
public void unregisterOperator(String name)