Package com.codetaco.math.impl
Class EquImpl
- java.lang.Object
-
- com.codetaco.math.impl.EquImpl
-
public class EquImpl extends Object
Create an instance of this class and send it an evaluate() message. The result will always be an instance of Double or String or ZonedDateTime.
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 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.
-
-
Constructor Summary
Constructors Constructor Description EquImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
compile(String _equ)
Object
evaluate()
Object
evaluate(String _equ)
Function
function(com.codetaco.math.impl.token.TokVariable varTok)
Set<String>
gatherVariables()
Date
getBaseDate()
static EquImpl
getInstance()
static EquImpl
getInstance(boolean fresh)
static EquImpl
getInstance(com.codetaco.math.impl.support.EquationSupport support)
org.apache.commons.codec.language.Metaphone
getMetaphone()
com.codetaco.math.impl.support.EquationSupport
getSupport()
void
initialize()
Operator
operator(com.codetaco.math.impl.token.Token tok)
void
registerFunction(String name, Class<?> functionSubclass)
void
setBaseDate(Date newBaseDate)
EquImpl
setSupport(com.codetaco.math.impl.support.EquationSupport newSupport)
String
showRPN()
void
showRPN(StringBuilder sb)
String
toString()
void
unregisterFunction(String name)
void
unregisterOperator(String name)
-
-
-
Method Detail
-
getInstance
public static EquImpl getInstance(com.codetaco.math.impl.support.EquationSupport support)
-
getInstance
public static EquImpl getInstance()
-
getInstance
public static EquImpl getInstance(boolean fresh)
-
compile
public void compile(String _equ)
-
evaluate
public Object evaluate()
-
function
public Function function(com.codetaco.math.impl.token.TokVariable varTok)
-
getBaseDate
public Date getBaseDate()
-
getMetaphone
public org.apache.commons.codec.language.Metaphone getMetaphone()
-
getSupport
public com.codetaco.math.impl.support.EquationSupport getSupport()
-
initialize
public void initialize()
-
operator
public Operator operator(com.codetaco.math.impl.token.Token tok)
-
setBaseDate
public void setBaseDate(Date newBaseDate)
-
setSupport
public EquImpl setSupport(com.codetaco.math.impl.support.EquationSupport newSupport)
-
showRPN
public String showRPN()
-
showRPN
public void showRPN(StringBuilder sb)
-
unregisterFunction
public void unregisterFunction(String name)
-
unregisterOperator
public void unregisterOperator(String name)
-
-