Class AbstractEvaluator

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object evaluate​(java.lang.String expression)
      Evaluates the given infix expression, returning the result.
      java.lang.Object evaluate​(SyntaxTree syntaxTree)
      Evaluates the given syntax tree, returning the result.
      java.lang.Object get​(Variable v)
      Gets the value of the given variable.
      ExpressionParser getParser()
      Gets the parser used when evaluating expressions.
      boolean isStrict()
      Gets whether the evaluator is operating in strict mode.
      void set​(Variable v, java.lang.Object value)
      Sets the value of the given variable.
      void setAll​(java.util.Map<? extends java.lang.String,​? extends java.lang.Object> map)
      Assigns variables en masse.
      void setStrict​(boolean strict)
      Sets whether the evaluator is operating in strict mode.
      java.lang.Object value​(java.lang.Object token)
      Gets the value of the given token.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractEvaluator

        public AbstractEvaluator()
    • Method Detail

      • setStrict

        public void setStrict​(boolean strict)
        Description copied from interface: Evaluator
        Sets 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 IllegalArgumentException with an "Unknown variable" message; in non-strict mode, such a variable will instead be resolved to an object of type Unresolved with 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=bar will complete successfully in non-strict mode, with the variable foo containing an object of type Unresolved and 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, the DefaultEvaluator will fail with an "Unsupported binary operator" exception when given the expression foo+bar, since foo and bar are unresolved variables, and the + operator cannot handle such objects.

        Specified by:
        setStrict in interface Evaluator
      • evaluate

        public java.lang.Object evaluate​(SyntaxTree syntaxTree)
        Description copied from interface: Evaluator
        Evaluates the given syntax tree, returning the result.
        Specified by:
        evaluate in interface Evaluator
      • evaluate

        public java.lang.Object evaluate​(java.lang.String expression)
        Description copied from interface: Evaluator
        Evaluates the given infix expression, returning the result.
        Specified by:
        evaluate in interface Evaluator
      • value

        public java.lang.Object value​(java.lang.Object token)
        Description copied from interface: Evaluator
        Gets 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.
        Specified by:
        value in interface Evaluator
      • get

        public java.lang.Object get​(Variable v)
        Description copied from interface: Evaluator
        Gets the value of the given variable.
        Specified by:
        get in interface Evaluator
      • set

        public void set​(Variable v,
                        java.lang.Object value)
        Description copied from interface: Evaluator
        Sets the value of the given variable.
        Specified by:
        set in interface Evaluator
      • setAll

        public void setAll​(java.util.Map<? extends java.lang.String,​? extends java.lang.Object> map)
        Description copied from interface: Evaluator
        Assigns variables en masse.
        Specified by:
        setAll in interface Evaluator