Package com.singularsys.jep.functions
Class LazyLogical
java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.functions.LazyLogical
- All Implemented Interfaces:
CallbackEvaluationI
,PostfixMathCommandI
,Serializable
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 evaluated1 || arg2
arg2 is not evaluated and true is returned0 && arg2
arg2 is not evaluated and false is returned1 && arg2
arg2 is evaluated
- Since:
- 3.1
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
static final int
protected final int
Represents which logical operator this is.static final int
Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, name, NaN, numberOfParameters
-
Constructor Summary
ConstructorDescriptionLazyLogical
(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
Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, checkNumberOfParameters, getName, getNumberOfParameters, run, setCurNumberOfParameters, setName, toString, toString
-
Field Details
-
id
protected final int idRepresents which logical operator this is. -
AND
public static final int AND- See Also:
-
OR
public static final int OR- See Also:
-
allowNumbers
protected boolean allowNumbers
-
-
Constructor Details
-
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 one of the constantsAND
orOR
.
-
LazyLogical
public LazyLogical(int id_in, boolean disallowNumbers) Constructor which restricts type of arguments.- Parameters:
id_in
- Either AND or ORdisallowNumbers
- if true Number arguments will raise exceptions, otherwise as the Standard constructor.
-
-
Method Details
-
evaluate
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 callpv.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 interfaceCallbackEvaluationI
- Parameters:
node
- The current nodepv
- 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:
-
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
-