com.singularsys.jep.functions

## Class LazyLogical

- java.lang.Object
- - com.singularsys.jep.functions.PostfixMathCommand
  - - com.singularsys.jep.functions.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 Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `allowNumbers`
    `static int` | `AND`
    `protected int` | `id` Represents which logical operator this is.
    `static int` | `OR`

    - ### Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand

      `curNumberOfParameters, name, NaN, numberOfParameters`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LazyLogical(int id_in)` Standard constructor, non zero Numbers will be treated as true and zero Numbers as false.
    `LazyLogical(int id_in, boolean disallowNumbers)` Constructor which restricts type of arguments.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.Object` | `evaluate(Node node, Evaluator pv)` Performs some special evaluation on the node.
    `int` | `getId()` Return a code indicating the type of this operator
    `boolean` | `isAllowNumbers()` Returns whether numbers are treated as booleans

    - ### Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand

      `asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, checkNumberOfParameters, getName, getNumberOfParameters, run, setCurNumberOfParameters, setName, toString, toString`

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

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

- - ### Field Detail

    - #### id

          protected int id

      Represents which logical operator this is.

    - #### AND

          public static final int AND

      See Also:
        Constant Field Values

    - #### OR

          public static final int OR

      See Also:
        Constant Field Values

    - #### 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

Copyright © 2018 Singular Systems http://www.singularsys.com/jep