public class ArithmeticExpression extends ValueExpression
Modifier and Type | Field and Description |
---|---|
static int |
ADDITION |
static int |
DIVIDE |
static int |
MODULUS |
static int |
MULTIPLY |
static int |
SUBTRACT |
Constructor and Description |
---|
ArithmeticExpression() |
Modifier and Type | Method and Description |
---|---|
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.
|
getValue
isBracketed, setBracketed
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
public Class getExpectedReturnType(Query q) throws QueryParseException
getExpectedReturnType
in class Expression
q
- 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 Expression
o
- 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 Expression
q
- The Query object.LHS.hasFixedResult(Query)
&&
RHS.hasFixedResult(Query)
public void init(Query q) throws QueryParseException
Expression
init
in class Expression
q
- 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 ValueExpression
o
- 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