T - The type of values handled by the evaluatorpublic abstract class AbstractEvaluator<T>
extends java.lang.Object
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractEvaluator(Parameters parameters)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected T |
evaluate(Constant constant,
java.lang.Object evaluationContext)
Evaluates a constant.
|
protected T |
evaluate(Function function,
java.util.Iterator<T> arguments,
java.lang.Object evaluationContext)
Evaluates a function.
|
protected T |
evaluate(Operator operator,
java.util.Iterator<T> operands,
java.lang.Object evaluationContext)
Evaluates an operation.
|
T |
evaluate(java.lang.String expression)
Evaluates an expression.
|
T |
evaluate(java.lang.String expression,
java.lang.Object evaluationContext)
Evaluates an expression that contains variables.
|
java.util.Collection<Constant> |
getConstants()
Gets the constants supported by this evaluator.
|
java.util.Collection<Function> |
getFunctions()
Gets the functions supported by this evaluator.
|
java.util.Collection<Operator> |
getOperators()
Gets the operators supported by this evaluator.
|
protected Operator |
guessOperator(Token previous,
java.util.List<Operator> candidates)
When a token can be more than one operator (homonym operators), this method guesses the right operator.
|
protected abstract T |
toValue(java.lang.String literal,
java.lang.Object evaluationContext)
Evaluates a literal (Converts it to a value).
|
protected void |
validateHomonyms(java.util.List<Operator> operators)
Validates that homonym operators are valid.
|
protected AbstractEvaluator(Parameters parameters)
parameters - The evaluator parameters.
protected void validateHomonyms(java.util.List<Operator> operators)
operators - The operators to validate.java.lang.IllegalArgumentException - if the homonyms are not compatibles.guessOperator(Token, List)protected Operator guessOperator(Token previous, java.util.List<Operator> candidates)
previous - The last parsed tokens (the previous token in the infix expression we are evaluating).candidates - The candidate tokens.validateHomonyms(List)protected T evaluate(Constant constant, java.lang.Object evaluationContext)
constant - The constantevaluationContext - The context of the evaluationprotected T evaluate(Operator operator, java.util.Iterator<T> operands, java.lang.Object evaluationContext)
operator - The operatoroperands - The operandsevaluationContext - The context of the evaluationprotected T evaluate(Function function, java.util.Iterator<T> arguments, java.lang.Object evaluationContext)
function - The functionarguments - The function's argumentsevaluationContext - The context of the evaluationprotected abstract T toValue(java.lang.String literal, java.lang.Object evaluationContext)
literal - The literal to evaluate.evaluationContext - The context of the evaluationjava.lang.IllegalArgumentException - if the literal can't be converted to a value.public T evaluate(java.lang.String expression)
expression - The expression to evaluate.java.lang.IllegalArgumentException - if the expression is not correct.public T evaluate(java.lang.String expression, java.lang.Object evaluationContext)
expression - The expression to evaluate.evaluationContext - The context of the evaluation.
java.lang.IllegalArgumentException - if the expression is not correct.AbstractVariableSetpublic java.util.Collection<Operator> getOperators()
public java.util.Collection<Function> getFunctions()
public java.util.Collection<Constant> getConstants()