Class LazyLogical

  • All Implemented Interfaces:
    CallbackEvaluationI, PostfixMathCommandI, java.io.Serializable

    public class LazyLogical
    extends PostfixMathCommand
    implements CallbackEvaluationI
    A version of the logical operators which use lazy evaluation. The first argument is always evaluated but the second argument is only evaluated if needed. Hence
    • 0 || arg2 arg2 is evaluated
    • 1 || arg2 arg2 is not evaluated and true is returned
    • 0 && arg2 arg2 is not evaluated and false is returned
    • 1 && arg2 arg2 is evaluated
    Since:
    3.1
    See Also:
    Serialized Form
    • Field Detail

      • id

        protected int id
        Represents which logical operator this is.
      • allowNumbers

        protected boolean allowNumbers
    • Constructor Detail

      • LazyLogical

        public LazyLogical​(int id_in)
        Standard constructor, non zero Numbers will be treated as true and zero Numbers as false.
        Parameters:
        id_in - either of the constants AND or OR
      • LazyLogical

        public LazyLogical​(int id_in,
                           boolean disallowNumbers)
        Constructor which restricts type of arguments.
        Parameters:
        id_in - Either AND or OR
        disallowNumbers - if true Number arguments will raise exceptions, otherwise as the Standard constructor.
    • Method Detail

      • evaluate

        public java.lang.Object evaluate​(Node node,
                                         Evaluator pv)
                                  throws EvaluationException
        Description copied from interface: CallbackEvaluationI
        Performs some special evaluation on the node. This method has the responsibility for evaluating the children of the node and it should generally call
         pv.eval(node.jjtGetChild(i))   
         
        for each child. The SymbolTable is not passed as an argument. This is because it is better practice to get and set variable values by using node.getVar().setValue() rather that through the SymbolTable with requires a hashtable lookup.
        Specified by:
        evaluate in interface CallbackEvaluationI
        Parameters:
        node - The current node
        pv - The visitor, can be used evaluate the children
        Returns:
        the value after evaluation. This value will be passed to other functions higher up the node tree. The value can be any type including Double or Vector<Object>
        Throws:
        EvaluationException - if the calculation cannot be performed
        See Also:
        Evaluator
      • getId

        public int getId()
        Return a code indicating the type of this operator
        Returns:
        the id
        Since:
        3.4.0
      • isAllowNumbers

        public boolean isAllowNumbers()
        Returns whether numbers are treated as booleans
        Returns:
        true if numbers can be used
        Since:
        3.4.0