Package webwork.util
Class SimpleTest
java.lang.Object
webwork.util.SimpleTest
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intprotected static final charprotected static final intprotected intprotected static final intprotected static final charprotected Stringprotected Stringprotected static final intprotected static final charprotected static final intprotected static final intprotected static final charprotected static final intprotected booleanprotected booleanprotected SimpleTestprotected static final intprotected static final charprotected static final intprotected intprotected static final intprotected static final charprotected Queryprotected Queryprotected static final charprotected intprotected intprotected Objectprotected Object -
Constructor Summary
ConstructorsConstructorDescriptionSimpleTest(String exp) SimpleTest(SimpleTest prevTest, String exp) Create a SimpleTest for the expression exp, and make use of the values found in the previously evaluated expression prevText if possible -
Method Summary
Modifier and TypeMethodDescriptionprotected intcheckOperator(String str) Look through the expression to find any operators like invalid input: '&'invalid input: '&' or ||, invalid input: '<', > etc.protected ObjectgetConstant(String exp) This method checks if the expression is a constant value.static SimpleTestgetSimpleTest(String expression) Get a SimpleTest object for the expression.protected booleanresolve(int comp, int condition) determine true or false by comparing the comparison result with the operator.booleantest(ValueStack stack) protected booleantest(ValueStack stack, Object prevVal1, Object prevVal2) The values in prevVal1 and prevVal2 will always be sent in.
-
Field Details
-
NONE
protected static final int NONE- See Also:
-
AND
protected static final int AND- See Also:
-
OR
protected static final int OR- See Also:
-
AND_CHAR
protected static final char AND_CHAR- See Also:
-
OR_CHAR
protected static final char OR_CHAR- See Also:
-
QUOTE_CHAR
protected static final char QUOTE_CHAR- See Also:
-
EQUAL_CHAR
protected static final char EQUAL_CHAR- See Also:
-
NOT_CHAR
protected static final char NOT_CHAR- See Also:
-
GREATER_CHAR
protected static final char GREATER_CHAR- See Also:
-
LESS_CHAR
protected static final char LESS_CHAR- See Also:
-
CHECK_NULL
protected static final int CHECK_NULL- See Also:
-
EQUAL
protected static final int EQUAL- See Also:
-
NOT_EQUAL
protected static final int NOT_EQUAL- See Also:
-
GREATER
protected static final int GREATER- See Also:
-
GREATER_EQUAL
protected static final int GREATER_EQUAL- See Also:
-
LESS
protected static final int LESS- See Also:
-
LESS_EQUAL
protected static final int LESS_EQUAL- See Also:
-
condition
protected int condition -
neg1
protected boolean neg1 -
neg2
protected boolean neg2 -
q1
-
q2
-
exp1
-
exp2
-
value1
-
value2
-
nextTest
-
operator
protected int operator -
sameVal1
protected int sameVal1 -
sameVal2
protected int sameVal2
-
-
Constructor Details
-
SimpleTest
public SimpleTest() -
SimpleTest
Create a SimpleTest for the expression exp, and make use of the values found in the previously evaluated expression prevText if possible- Throws:
ComplexException
-
SimpleTest
- Throws:
ComplexException
-
-
Method Details
-
getSimpleTest
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
Look through the expression to find any operators like invalid input: '&'invalid input: '&' or ||, invalid input: '<', > etc. If found then the operator variable is updated.- Throws:
ComplexException
-
getConstant
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
-
test
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 resultcondition- the condition- Returns:
- the boolean result
-