webwork.util
Class SimpleTest

java.lang.Object
  extended bywebwork.util.SimpleTest

public class SimpleTest
extends java.lang.Object

This class is used to handle test expressions in an efficient way. It is more than 5 times faster than the javacc generated Parser.java Instances of the class are retrieved through the static method getSimpleTest. If the method returns null it means the expression was too complex for this class too handle. Complex expressions are those using parenthesis to control the order of evaluation. Those expressions will instead be handled by the old javacc Parser.java class.

Version:
$Revision: 1.2 $
Author:
Dick Zetterberg (dick@transitor.se)
See Also:
ValueStack, ComplexException, Parser

Field Summary
protected static int AND
           
protected static char AND_CHAR
           
protected static int CHECK_NULL
           
protected  int condition
           
protected static int EQUAL
           
protected static char EQUAL_CHAR
           
protected  java.lang.String exp1
           
protected  java.lang.String exp2
           
protected static int GREATER
           
protected static char GREATER_CHAR
           
protected static int GREATER_EQUAL
           
protected static int LESS
           
protected static char LESS_CHAR
           
protected static int LESS_EQUAL
           
protected  boolean neg1
           
protected  boolean neg2
           
protected  SimpleTest nextTest
           
protected static int NONE
           
protected static char NOT_CHAR
           
protected static int NOT_EQUAL
           
protected  int operator
           
protected static int OR
           
protected static char OR_CHAR
           
protected  Query q1
           
protected  Query q2
           
protected static char QUOTE_CHAR
           
protected  int sameVal1
           
protected  int sameVal2
           
protected  java.lang.Object value1
           
protected  java.lang.Object value2
           
 
Constructor Summary
SimpleTest()
           
SimpleTest(SimpleTest prevTest, java.lang.String exp)
          Create a SimpleTest for the expression exp, and make use of the values found in the previously evaluated expression prevText if possible
SimpleTest(java.lang.String exp)
           
 
Method Summary
protected  int checkOperator(java.lang.String str)
          Look through the expression to find any operators like && or ||, <, > etc.
protected  java.lang.Object getConstant(java.lang.String exp)
          This method checks if the expression is a constant value.
static SimpleTest getSimpleTest(java.lang.String expression)
          Get a SimpleTest object for the expression.
protected  boolean resolve(int comp, int condition)
          determine true or false by comparing the comparison result with the operator.
 boolean test(ValueStack stack)
           
protected  boolean test(ValueStack stack, java.lang.Object prevVal1, java.lang.Object prevVal2)
          The values in prevVal1 and prevVal2 will always be sent in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONE

protected static final int NONE
See Also:
Constant Field Values

AND

protected static final int AND
See Also:
Constant Field Values

OR

protected static final int OR
See Also:
Constant Field Values

AND_CHAR

protected static final char AND_CHAR
See Also:
Constant Field Values

OR_CHAR

protected static final char OR_CHAR
See Also:
Constant Field Values

QUOTE_CHAR

protected static final char QUOTE_CHAR
See Also:
Constant Field Values

EQUAL_CHAR

protected static final char EQUAL_CHAR
See Also:
Constant Field Values

NOT_CHAR

protected static final char NOT_CHAR
See Also:
Constant Field Values

GREATER_CHAR

protected static final char GREATER_CHAR
See Also:
Constant Field Values

LESS_CHAR

protected static final char LESS_CHAR
See Also:
Constant Field Values

CHECK_NULL

protected static final int CHECK_NULL
See Also:
Constant Field Values

EQUAL

protected static final int EQUAL
See Also:
Constant Field Values

NOT_EQUAL

protected static final int NOT_EQUAL
See Also:
Constant Field Values

GREATER

protected static final int GREATER
See Also:
Constant Field Values

GREATER_EQUAL

protected static final int GREATER_EQUAL
See Also:
Constant Field Values

LESS

protected static final int LESS
See Also:
Constant Field Values

LESS_EQUAL

protected static final int LESS_EQUAL
See Also:
Constant Field Values

condition

protected int condition

neg1

protected boolean neg1

neg2

protected boolean neg2

q1

protected Query q1

q2

protected Query q2

exp1

protected java.lang.String exp1

exp2

protected java.lang.String exp2

value1

protected java.lang.Object value1

value2

protected java.lang.Object value2

nextTest

protected SimpleTest nextTest

operator

protected int operator

sameVal1

protected int sameVal1

sameVal2

protected int sameVal2
Constructor Detail

SimpleTest

public SimpleTest()

SimpleTest

public SimpleTest(SimpleTest prevTest,
                  java.lang.String exp)
           throws ComplexException
Create a SimpleTest for the expression exp, and make use of the values found in the previously evaluated expression prevText if possible


SimpleTest

public SimpleTest(java.lang.String exp)
           throws ComplexException
Method Detail

getSimpleTest

public static SimpleTest getSimpleTest(java.lang.String expression)
Get a SimpleTest object for the expression. If the expression is too complex then null is returned If the expression has been handled before then a cached SimpleTest object is returned. Otherwise a new one is created


checkOperator

protected int checkOperator(java.lang.String str)
                     throws ComplexException
Look through the expression to find any operators like && or ||, <, > etc. If found then the operator variable is updated.

Throws:
ComplexException

getConstant

protected java.lang.Object getConstant(java.lang.String exp)
This method checks if the expression is a constant value. If it is not a constant then the method returns the object NO_CONSTANT If it is a constant then it returns the constant value which may be null


test

public boolean test(ValueStack stack)

test

protected boolean test(ValueStack stack,
                       java.lang.Object prevVal1,
                       java.lang.Object prevVal2)
The values in prevVal1 and prevVal2 will always be sent in. They can be null because they are not used or because the value found was null. This does not matter. The expression after this one will only care about the value IF the same expression existed in this test as in the next test.


resolve

protected boolean resolve(int comp,
                          int condition)
determine true or false by comparing the comparison result with the operator.

Parameters:
comp - the comparison result
condition - the condition
Returns:
the boolean result


Copyright © 2001-2003 WebWork All Rights Reserved.