Package com.singularsys.jep.standard

# Class FastEvaluator

java.lang.Object
com.singularsys.jep.standard.FastEvaluator

All Implemented Interfaces:
  `Evaluator`, `GenericVisitor<Object,Void,EvaluationException>`, `JepComponent`, `Serializable`

Direct Known Subclasses:
  `MonitoringEvaluator`, `ThreadSafeEvaluator`

public class FastEvaluator extends Object implements Evaluator, GenericVisitor<Object,Void,EvaluationException>
A fast evaluator for Jep expressions. This is the default evaluator used by Jep.

It differs from `StandardEvaluator` in the evaluation of functions. It uses the `UnaryFunction.eval(Object)`, `BinaryFunction.eval(Object, Object)`, `NaryBinaryFunction.eval(Object, Object)`, `NaryFunction.eval(Object[])` methods instead of the `PostfixMathCommandI.run(Stack)` method. It can be up-to 6 times generally faster than the StandardEvaluator but if most functions don't use these interfaces then it can be marginally slower.

The `UncheckedEvaluator` uses a similar approach but does fewer intermediate checks and is about 5% faster than this class.

Since Jep 4.1, extension 2.2, this now implements `GenericVisitor` some method signatures have changed to be more specific.

Since:
  Jep 3.3
See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected boolean`
  `trapInfinity`
  `protected boolean`
  `trapNaN`
  `protected boolean`
  `trapNullValues`
  `protected boolean`
  `trapUnsetValues`
  Whether null values for variables are trapped

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `FastEvaluator()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Object`
  `eval(Node node)`
  Evaluates a sub expression.
  `Object`
  `evaluate(Node node)`
  Main entry point, evaluates a node and returns and object with the value of the node.
  `JepComponent`
  `getLightWeightInstance()`
  Gets a light-weight instance suitable for using in multiple threads.
  `void`
  `init(Jep jep)`
  Initialize the component.
  `boolean`
  `isTrapInfinity()`
  `boolean`
  `isTrapNaN()`
  `boolean`
  `isTrapNullValues()`
  Whether null values for variables are trapped.
  `boolean`
  `isTrapUnsetValues()`
  Whether variables with unset values are trapped.
  `EvaluationException`
  `makeException(String message)`
  Create an Exception of the correct type.
  `protected Object`
  `nodeAccept(Node node)`
  `void`
  `setTrapInfinity(boolean trapInfinity)`
  `void`
  `setTrapNaN(boolean trapNaN)`
  `void`
  `setTrapNullValues(boolean trapNullValues)`
  Sets whether null values for variables are trapped.
  `void`
  `setTrapUnsetValues(boolean trapUnsetValues)`
  Sets whether unset variable values are trapped.
  `Object`
  `visit(ASTConstant node, Void data)`
  Visit a constant node
  `Object`
  `visit(ASTFunNode node, Void data)`
  Visit a function node
  `Object`
  `visit(ASTOpNode node, Void data)`
  Visit an operator node
  `Object`
  `visit(ASTVarNode node, Void data)`
  Visit a variable node
  `Object`
  `visitConstant(Node node)`
  `protected Object`
  `visitFun(Node node)`
  Visits a function/operator node.
  `Object`
  `visitVar(Node node)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface com.singularsys.jep.Evaluator

  `eval`

  ### Methods inherited from interface com.singularsys.jep.GenericVisitor

  `makeException, visit, visitChildren`

- ## Field Details

  - ### trapUnsetValues

    protected boolean trapUnsetValues
    Whether null values for variables are trapped

  - ### trapNullValues

    protected boolean trapNullValues

  - ### trapNaN

    protected boolean trapNaN

  - ### trapInfinity

    protected boolean trapInfinity

- ## Constructor Details

  - ### FastEvaluator

    public FastEvaluator()

- ## Method Details

  - ### init

    public void init(Jep jep)
    Description copied from interface: `JepComponent`
    Initialize the component. This method is called whenever a component is added to Jep. Hence, it allows components to keep track of the other components they may rely on.
    Specified by:
      `init` in interface `JepComponent`
    Parameters:
      `jep` - the current Jep instance

  - ### eval

    public Object eval(Node node) throws EvaluationException
    Description copied from interface: `Evaluator`
    Evaluates a sub expression. This method can be called by PostfixMathCommands which implement `CallbackEvaluationI`
    Specified by:
      `eval` in interface `Evaluator`
    Parameters:
      `node` - node to evaluate
    Returns:
      The value after evaluating the sub expression.
    Throws:
      `EvaluationException` - if errors occur during evaluation;

  - ### evaluate

    public Object evaluate(Node node) throws EvaluationException
    Description copied from interface: `Evaluator`
    Main entry point, evaluates a node and returns and object with the value of the node.
    Specified by:
      `evaluate` in interface `Evaluator`
    Parameters:
      `node` - node to evaluate
    Returns:
      value after evaluation
    Throws:
      `EvaluationException` - if errors occur during evaluation;

  - ### nodeAccept

    protected Object nodeAccept(Node node) throws EvaluationException
    Throws:
      `EvaluationException`

  - ### visit

    public Object visit(ASTConstant node, Void data) throws EvaluationException
    Description copied from interface: `GenericVisitor`
    Visit a constant node
    Specified by:
      `visit` in interface `GenericVisitor<Object,Void,EvaluationException>`
    Parameters:
      `node` - current node
      `data` - context data
    Returns:
      the result of visiting the node
    Throws:
      `EvaluationException`

  - ### visitConstant

    public Object visitConstant(Node node) throws EvaluationException
    Throws:
      `EvaluationException`

  - ### visit

    public Object visit(ASTVarNode node, Void data) throws EvaluationException
    Description copied from interface: `GenericVisitor`
    Visit a variable node
    Specified by:
      `visit` in interface `GenericVisitor<Object,Void,EvaluationException>`
    Parameters:
      `node` - current node
      `data` - context data
    Returns:
      the result of visiting the node
    Throws:
      `EvaluationException`

  - ### visitVar

    public Object visitVar(Node node) throws EvaluationException
    Throws:
      `EvaluationException`

  - ### visit

    public Object visit(ASTFunNode node, Void data) throws EvaluationException
    Description copied from interface: `GenericVisitor`
    Visit a function node
    Specified by:
      `visit` in interface `GenericVisitor<Object,Void,EvaluationException>`
    Parameters:
      `node` - current node
      `data` - context data
    Returns:
      the result of visiting the node
    Throws:
      `EvaluationException`

  - ### visit

    public Object visit(ASTOpNode node, Void data) throws EvaluationException
    Description copied from interface: `GenericVisitor`
    Visit an operator node
    Specified by:
      `visit` in interface `GenericVisitor<Object,Void,EvaluationException>`
    Parameters:
      `node` - current node
      `data` - context data
    Returns:
      the result of visiting the node
    Throws:
      `EvaluationException`

  - ### visitFun

    protected Object visitFun(Node node) throws EvaluationException
    Visits a function/operator node. This is the most visited method for most expression evaluations. Keeping it fast is important.
    Parameters:
      `node` -
    Throws:
      `EvaluationException`

  - ### isTrapUnsetValues

    public boolean isTrapUnsetValues()
    Whether variables with unset values are trapped.
    Returns:
    Since:
      3.5

  - ### setTrapUnsetValues

    public void setTrapUnsetValues(boolean trapUnsetValues)
    Sets whether unset variable values are trapped. This flag is set by when the `Variable.setValidValue(boolean)` or cleared using `VariableTable.clearValues()`.
    Parameters:
      `trapUnsetValues` - true to trap unset values, false to ignore them
    Since:
      3.5

  - ### isTrapNullValues

    public boolean isTrapNullValues()
    Whether null values for variables are trapped.
    Returns:
      the status if the trap null values flag.

  - ### setTrapNullValues

    public void setTrapNullValues(boolean trapNullValues)
    Sets whether null values for variables are trapped. If set (the default) then an EvaluationException is thrown for null values of variables. If not set then null values are passed to PostfixMathCommands who will need to test for null values.
    Parameters:
      `trapNullValues` -

  - ### isTrapNaN

    public boolean isTrapNaN()

  - ### setTrapNaN

    public void setTrapNaN(boolean trapNaN)

  - ### isTrapInfinity

    public boolean isTrapInfinity()

  - ### setTrapInfinity

    public void setTrapInfinity(boolean trapInfinity)

  - ### getLightWeightInstance

    public JepComponent getLightWeightInstance()
    Description copied from interface: `JepComponent`
    Gets a light-weight instance suitable for using in multiple threads.
    Specified by:
      `getLightWeightInstance` in interface `JepComponent`
    Returns:
      a new FastEvaluator

  - ### makeException

    public EvaluationException makeException(String message)
    Description copied from interface: `GenericVisitor`
    Create an Exception of the correct type. A typical implementation is

        @Override
        public JepException makeException(String message) {
         return new JepException(message);
        }

    Specified by:
      `makeException` in interface `GenericVisitor<Object,Void,EvaluationException>`
    Parameters:
      `message` - error message
    Returns:
      an Exception