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)
gatherVariables.
|
Date |
getBaseDate() |
static Equ |
getInstance() |
static Equ |
getInstance(boolean fresh) |
org.apache.commons.codec.language.Metaphone |
getMetaphone() |
EquationSupport |
getSupport()
Getter for the field
support . |
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 Set<String> gatherVariables(List<EquPart> tokens)
gatherVariables.
tokens
- a Collection
object.Set
object.public static Equ getInstance()
public static Equ getInstance(boolean fresh)
public Function function(TokVariable varTok) throws Exception
Exception
public Date getBaseDate()
public org.apache.commons.codec.language.Metaphone getMetaphone()
public EquationSupport getSupport()
Getter for the field support
.
EquationSupport
object.protected void initializeSupport()
protected List<EquPart> negatize(List<EquPart> equParts)
public void registerFunction(String name, Class<?> functionSubclass) throws Exception
Exception
public void registerOperator(String name, Class<?> operatorSubclass) throws Exception
Exception
protected List<EquPart> rpnize(List<EquPart> oldTokens)
oldTokens
- a Collection
object.Collection
object.public void setBaseDate(Date newBaseDate)
public void setSupport(EquationSupport newSupport)
public void showRPN(StringBuilder sb) throws Exception
Exception
Copyright © 2018 CodeTaco. All rights reserved.