| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.josql.expressions.Expression
org.josql.expressions.ValueExpression
org.josql.expressions.ArithmeticExpression
public class ArithmeticExpression
Represents the arithmetic expressions: *, +, /, - and %. It should be noted that ALL numbers in JoSQL are represented as double values, this allows for easy arithmetic operations without the fear of losing precision or casting issues.
| Field Summary | |
|---|---|
| static int | ADDITION | 
| static int | DIVIDE | 
| static int | MODULUS | 
| static int | MULTIPLY | 
| static int | SUBTRACT | 
| Constructor Summary | |
|---|---|
| ArithmeticExpression() | |
| Method Summary | |
|---|---|
|  Object | evaluate(Object o,
         Query q)Evaulate this expression. | 
|  Class | getExpectedReturnType(Query q)Return the expected return type. | 
|  ValueExpression | getLeft()Get the LHS value expression. | 
|  ValueExpression | getRight()Get the RHS value expression. | 
|  int | getType() | 
|  boolean | hasFixedResult(Query q)Return whether this expression has a fixed result. | 
|  void | init(Query q)Perform the necessary initialisation for this expression. | 
|  boolean | isTrue(Object o,
       Query q)Determine whether this arithmetic expression evaluates to true. | 
|  void | setLeft(ValueExpression exp) | 
|  void | setRight(ValueExpression exp) | 
|  void | setType(int t) | 
|  String | toString()Return a string representation of the expression, making this abstract forces sub-classes to provide an implementation. | 
| Methods inherited from class org.josql.expressions.ValueExpression | 
|---|
| getValue | 
| Methods inherited from class org.josql.expressions.Expression | 
|---|
| isBracketed, setBracketed | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait | 
| Field Detail | 
|---|
public static final int MULTIPLY
public static final int ADDITION
public static final int SUBTRACT
public static final int DIVIDE
public static final int MODULUS
| Constructor Detail | 
|---|
public ArithmeticExpression()
| Method Detail | 
|---|
public Class getExpectedReturnType(Query q)
                            throws QueryParseException
getExpectedReturnType in class Expressionq - The Query object.
QueryParseException - If something goes wrong in determining the return type.
public boolean isTrue(Object o,
                      Query q)
               throws QueryExecutionException
Thus the following could be performed:
SELECT 10 + 20 FROM java.lang.ObjectThe rules are as follows:
evaluate(Object,Query) returns null then false
       is returned.evaluate(Object,Query) returns a number and it is greater than 0 then
       true is returned.  If it is 0 or less than 0 
       then false is returned.
   true is returned.
 
isTrue in class Expressiono - The object to perform the expression on.q - The Query object.
QueryExecutionException - If something goes wrong during the evaluation of the 
                                 expression.public boolean hasFixedResult(Query q)
hasFixedResult in class Expressionq - The Query object.
LHS.hasFixedResult(Query) 
         && 
         RHS.hasFixedResult(Query)
public void init(Query q)
          throws QueryParseException
Expression
init in class Expressionq - The Query object.
QueryParseException - If something goes wrong with the initialisation.public ValueExpression getRight()
public ValueExpression getLeft()
public void setLeft(ValueExpression exp)
public void setRight(ValueExpression exp)
public int getType()
public void setType(int t)
public Object evaluate(Object o,
                       Query q)
                throws QueryExecutionException
java.lang.Number otherwise a QueryExecutionException is
 thrown.
 Special cases:
evaluate in class ValueExpressiono - The object to perform the expression on.q - The Query object.
QueryExecutionException - If an error occurs during processing.public String toString()
Expression
toString in class Expression| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||