|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.christopherschultz.evaluator.Expression net.christopherschultz.evaluator.BinaryOperatorExpression
public class BinaryOperatorExpression
An expression to describe expressions with binary operators.
The operators supported are limited only by the parser's ability to recognize the operator as a binary (probably mathematical) expression, and the availability of a function which matches the operator.
Constructor Summary | |
---|---|
BinaryOperatorExpression(Expression left,
String operator,
Expression right)
Creates a new BinaryOperatorExpression with the specified sub expressions and operator. |
Method Summary | |
---|---|
void |
acceptVisitor(ExpressionVisitor visitor)
Accepts an ExpressionVisitor. |
boolean |
equals(Object o)
Returns true if the specified object is equal to
this one. |
Object |
evaluate(EvaluationContext ec)
Evaluates this Expression by returning the appropriate combination of the left and right-hand sub expressions with the operator. |
Expression |
getLeftExpression()
Gets the expression which is the left-hand operand of this binary operator. |
String |
getOperator()
Gets the operator for this BinaryOperatorExpression. |
Expression |
getRightExpression()
Gets the expression which is the right-hand operand of this binary operator. |
List |
getSubExpressions()
Returns a List containing both sides of this binary BinaryOperatorExpression. |
int |
hashCode()
|
String |
toString()
Returns an infix String representation of this BinaryOperatorExpression. |
Methods inherited from class net.christopherschultz.evaluator.Expression |
---|
getParent, setParent |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public BinaryOperatorExpression(Expression left, String operator, Expression right) throws EvaluationException
left
- The left-hand operand of this binary expresssion.operator
- The operator to be used (i.e. "+", "-", "&&", etc.)right
- The right-hand operand of this binary expresssion.
IllegalArgumentException
- If either of the sub-expressions
are null
, or the operator
is not recognized.
EvaluationException
Method Detail |
---|
public Expression getLeftExpression()
public String getOperator()
Gets the operator for this BinaryOperatorExpression.
Note that the operator is nothing magic: it's just the name of a function that will be looked-up in the EvaluationContext to determine which function to invoke on the two arguments.
public Expression getRightExpression()
public List getSubExpressions()
getSubExpressions
in class Expression
public void acceptVisitor(ExpressionVisitor visitor)
Expression
acceptVisitor
in class Expression
public Object evaluate(EvaluationContext ec) throws EvaluationException
Integer
s). Logical and relational operators return objects of
type Boolean
.
evaluate
in class Expression
ec
- The EvaluationContext in which this expression should
be evaluated.
EvaluationException
- If there is a problem performing the
mathematical operation (which is
a function).public String toString()
toString
in class Object
public boolean equals(Object o)
true
if the specified object is equal to
this one.
equals
in class Object
o
- The object to test for equality.
true
if the specified object is equal to
this one, false
otherwise.public int hashCode()
hashCode
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |