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