public class DoubleEvaluator extends Object
double numbers.| Modifier and Type | Field and Description |
|---|---|
static double |
EPSILON |
| Constructor and Description |
|---|
DoubleEvaluator() |
DoubleEvaluator(ASTNode node) |
| Modifier and Type | Method and Description |
|---|---|
void |
clearVariables()
Clear all defined variables for this evaluator.
|
void |
defineVariable(String variableName,
BooleanVariable value)
Define a boolean value for a given variable name.
|
void |
defineVariable(String variableName,
IDoubleValue value)
Define a value for a given variable name.
|
double |
evaluate()
Reevaluate the
expression (possibly after a new Variable
assignment) |
double |
evaluate(String expression)
Parse the given
expression String and evaluate it to a double
value |
double |
evaluateFunction(FunctionNode functionNode)
Evaluate an already parsed in
FunctionNode into a
souble number value. |
boolean |
evaluateFunctionLogical(FunctionNode functionNode) |
double |
evaluateNode(ASTNode node)
Evaluate an already parsed in abstract syntax tree node into a
double number value. |
boolean |
evaluateNodeLogical(ASTNode node) |
IDoubleCallbackFunction |
getCallbackFunction()
A callback function for unknown function names.
|
IDoubleValue |
getVariable(String variableName)
Returns the double variable value to which the specified variableName is
mapped, or
null if this map contains no mapping for the
variableName. |
static void |
getVariables(ASTNode node,
Set<String> result)
Get the variable names from the given AST node.
|
static void |
getVariables(String expression,
Set<String> result)
Get the variable names from the given expression.
|
ASTNode |
optimizeFunction(FunctionNode functionNode)
Optimize an already parsed in
functionNode into an
ASTNode. |
ASTNode |
parse(String expression)
Parse the given
expression String and store the resulting
ASTNode in this DoubleEvaluator |
static ASTNode |
parseNode(String expression)
Parse the given
expression String and return the resulting
ASTNode |
void |
setCallbackFunction(IDoubleCallbackFunction callbackFunction)
Set a callback function for unknown function names.
|
public DoubleEvaluator()
public DoubleEvaluator(ASTNode node)
public IDoubleCallbackFunction getCallbackFunction()
public void setCallbackFunction(IDoubleCallbackFunction callbackFunction)
callbackFunction - the callback function to setpublic ASTNode parse(String expression)
expression String and store the resulting
ASTNode in this DoubleEvaluatorexpression - SyntaxErrorpublic static ASTNode parseNode(String expression)
expression String and return the resulting
ASTNodeexpression - SyntaxErrorpublic double evaluate(String expression)
expression String and evaluate it to a double
valueexpression - SyntaxErrorpublic double evaluate()
expression (possibly after a new Variable
assignment)expression - SyntaxErrorpublic double evaluateNode(ASTNode node)
double number value.node - abstract syntax tree nodeArithmeticException - if the node cannot be evaluated.public double evaluateFunction(FunctionNode functionNode)
FunctionNode into a
souble number value.functionNode - ArithmeticException - if the functionNode cannot be evaluated.public boolean evaluateNodeLogical(ASTNode node)
public boolean evaluateFunctionLogical(FunctionNode functionNode)
public ASTNode optimizeFunction(FunctionNode functionNode)
functionNode into an
ASTNode.functionNode - public void defineVariable(String variableName, IDoubleValue value)
variableName - value - public IDoubleValue getVariable(String variableName)
null if this map contains no mapping for the
variableName.variableName - public void defineVariable(String variableName, BooleanVariable value)
variableName - value - public void clearVariables()
public static void getVariables(String expression, Set<String> result)
expression - result - a set which contains the variable namesCopyright © 2015. All rights reserved.