public class DoubleEvaluator extends Object
double
numbers.Modifier and Type | Field and Description |
---|---|
static double |
EPSILON |
Constructor and Description |
---|
DoubleEvaluator()
Instantiates a new double evaluator.
|
DoubleEvaluator(ASTNode node)
Instantiates a new double evaluator.
|
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)
Evaluate function logical.
|
double |
evaluateNode(ASTNode node)
Evaluate an already parsed in abstract syntax tree node into a
double number value. |
boolean |
evaluateNodeLogical(ASTNode node)
Evaluate node logical.
|
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)
node
- the nodepublic 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 DoubleEvaluator.expression
- the expressionSyntaxError
- the syntax errorpublic static ASTNode parseNode(String expression)
expression String
and return the resulting
ASTNode.expression
- the expressionSyntaxError
- the syntax errorpublic double evaluate(String expression)
expression String
and evaluate it to a
double value.expression
- the expressionSyntaxError
- the syntax errorpublic double evaluate()
expression
(possibly after a new Variable
assignment).SyntaxError
- the syntax errorpublic 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
- the function nodeArithmeticException
- if the functionNode
cannot be evaluated.public boolean evaluateNodeLogical(ASTNode node)
node
- the nodepublic boolean evaluateFunctionLogical(FunctionNode functionNode)
functionNode
- the function nodepublic ASTNode optimizeFunction(FunctionNode functionNode)
functionNode
into an
ASTNode
.functionNode
- the function nodepublic void defineVariable(String variableName, IDoubleValue value)
variableName
- the variable namevalue
- the valuepublic IDoubleValue getVariable(String variableName)
null
if this map contains no mapping for the
variableName.variableName
- the variable namepublic void defineVariable(String variableName, BooleanVariable value)
variableName
- the variable namevalue
- the valuepublic void clearVariables()
public static void getVariables(String expression, Set<String> result)
expression
- the expressionresult
- a set which contains the variable namesCopyright © 2017. All rights reserved.