public class AndOrExpression extends BinaryExpression
AND expression or a OR expression.
Lazy evaluation is employed here such if the expression is: LHS OR RHS
and LHS = true then the RHS is NOT evaluated, if the expression is: LHS AND RHS
and LHS = false then the RHS is NOT evaluated (see isTrue(Object,Query)). This is important to note if you expect
side-effects to occur in the RHS (bad practice anyway so don't do it!).left, right| Constructor and Description |
|---|
AndOrExpression() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
isAnd() |
boolean |
isTrue(Object o,
Query q)
Evaulates the expression and returns true if the expression evaulates to
true. |
void |
setAnd(boolean v) |
String |
toString()
Return a string version of this expression.
|
getExpectedReturnType, getLeft, getRight, getValue, hasFixedResult, init, setLeft, setRightisBracketed, setBracketedpublic boolean isAnd()
public void setAnd(boolean v)
public boolean isTrue(Object o, Query q) throws QueryExecutionException
true.
| Type | LHS | RHS | Result | Notes |
|---|---|---|---|---|
| AND | true | true | true | Both LHS and RHS are evaulated. |
| AND | true | false | false | Both LHS and RHS are evaulated. |
| AND | false | unknown or false | false | Only the LHS is evaulated. |
| OR | true | unknown | true | Only the LHS is evaulated. |
| OR | false | true | true | Both the LHS and RHS are evaulated. |
| OR | false | false | false | Both the LHS and RHS are evaulated. |
In general what this means is that you should "left-weight" your expressions so that
the expression that returns true most often (or more likely to return
true) should be on the LHS.
isTrue in class Expressiono - The current object to perform the expression on.q - The query object.true if the expression evaulates to true, false
otherwise.QueryExecutionException - If the expression cannot be evaulated.public String toString()
toString in class Expression