Class AbstractEvaluator
- java.lang.Object
-
- org.scijava.parse.eval.AbstractEvaluator
-
- All Implemented Interfaces:
Evaluator
- Direct Known Subclasses:
AbstractStackEvaluator
public abstract class AbstractEvaluator extends java.lang.Object implements Evaluator
Base class forEvaluatorimplementations.- Author:
- Curtis Rueden
-
-
Constructor Summary
Constructors Constructor Description AbstractEvaluator()AbstractEvaluator(ExpressionParser parser)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectevaluate(java.lang.String expression)Evaluates the given infix expression, returning the result.java.lang.Objectevaluate(SyntaxTree syntaxTree)Evaluates the given syntax tree, returning the result.java.lang.Objectget(Variable v)Gets the value of the given variable.ExpressionParsergetParser()Gets the parser used when evaluating expressions.booleanisStrict()Gets whether the evaluator is operating in strict mode.voidset(Variable v, java.lang.Object value)Sets the value of the given variable.voidsetAll(java.util.Map<? extends java.lang.String,? extends java.lang.Object> map)Assigns variables en masse.voidsetStrict(boolean strict)Sets whether the evaluator is operating in strict mode.java.lang.Objectvalue(java.lang.Object token)Gets the value of the given token.
-
-
-
Constructor Detail
-
AbstractEvaluator
public AbstractEvaluator()
-
AbstractEvaluator
public AbstractEvaluator(ExpressionParser parser)
-
-
Method Detail
-
getParser
public ExpressionParser getParser()
Description copied from interface:EvaluatorGets the parser used when evaluating expressions.
-
isStrict
public boolean isStrict()
Description copied from interface:EvaluatorGets whether the evaluator is operating in strict mode.- Specified by:
isStrictin interfaceEvaluator- See Also:
Evaluator.setStrict(boolean)
-
setStrict
public void setStrict(boolean strict)
Description copied from interface:EvaluatorSets whether the evaluator is operating in strict mode. Evaluators operate in strict mode by default.When evaluating strictly, usage of an unassigned variable token in a place where its value is needed will generate an
IllegalArgumentExceptionwith an "Unknown variable" message; in non-strict mode, such a variable will instead be resolved to an object of typeUnresolvedwith the same name as the original variable.In cases such as assignment, this may be sufficient to complete the evaluation; for example, the expression
foo=barwill complete successfully in non-strict mode, with the variablefoocontaining an object of typeUnresolvedand token value"bar". But in cases where the unresolved value is needed as an input for additional operations, the evaluation may still ultimately fail of the operation in question is not defined for unresolved values. For example, theDefaultEvaluatorwill fail with an "Unsupported binary operator" exception when given the expressionfoo+bar, sincefooandbarare unresolved variables, and the+operator cannot handle such objects.
-
evaluate
public java.lang.Object evaluate(SyntaxTree syntaxTree)
Description copied from interface:EvaluatorEvaluates the given syntax tree, returning the result.
-
evaluate
public java.lang.Object evaluate(java.lang.String expression)
Description copied from interface:EvaluatorEvaluates the given infix expression, returning the result.
-
value
public java.lang.Object value(java.lang.Object token)
Description copied from interface:EvaluatorGets the value of the given token. For variables, returns the value of the variable, throwing an exception if the variable is not set. For literals, returns the token itself.
-
get
public java.lang.Object get(Variable v)
Description copied from interface:EvaluatorGets the value of the given variable.
-
set
public void set(Variable v, java.lang.Object value)
Description copied from interface:EvaluatorSets the value of the given variable.
-
-