com.singularsys.jep.functions
Class LazyLogical

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

Since:
3.1
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.singularsys.jep.functions.CallbackEvaluationI
CallbackEvaluationI.Runnable
 
Field Summary
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
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
 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
 void run(java.util.Stack<java.lang.Object> inStack)
          Run the function on the stack.
 
Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, checkNumberOfParameters, checkStack, getName, getNumberOfParameters, setCurNumberOfParameters, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, 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 -
disallowNumbers - if true Number arguments will raise exceptions, otherwise as the Standard constructor.
Method Detail

run

public void run(java.util.Stack<java.lang.Object> inStack)
         throws EvaluationException
Description copied from interface: PostfixMathCommandI
Run the function on the stack. Pops the arguments from the stack, and pushes the result on the top of the stack.

Specified by:
run in interface PostfixMathCommandI
Throws:
EvaluationException

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
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 © 2010 Singular Systems http://www.singularsys.com/jep