net.christopherschultz.evaluator
Class UnaryMinusExpression

java.lang.Object
  extended by net.christopherschultz.evaluator.Expression
      extended by net.christopherschultz.evaluator.UnaryMinusExpression

public class UnaryMinusExpression
extends Expression

An Expression to perform an arithmetic sign inversion (unary minus) of a sub-expression.

Version:
$Revision: 1.4 $ $Date: 2008-06-20 22:58:48 $
Author:
Chris Schultz

Constructor Summary
UnaryMinusExpression(Expression subExpression)
          Creates a new UnaryMinusExpression with the given sub-expression.
 
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 logical negation of the sub-expression.
 Expression getSubExpression()
          Gets the Expression which is being sign inverted by this one.
 List getSubExpressions()
          Returns a list containing this UnaryMinusExpression and the expression to be sign inverted (in that order).
 int hashCode()
          Returns the hash code for this UnaryMinusExpression.
 String toString()
          Returns a String representation of this UnaryMinusExpression.
 
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

UnaryMinusExpression

public UnaryMinusExpression(Expression subExpression)
                     throws EvaluationException
Creates a new UnaryMinusExpression with the given sub-expression.

Parameters:
subExpression - The expression whose result will be sign inverted when evaluated.
Throws:
IllegalArgumentException - If the sub expression is null.
EvaluationException
Method Detail

evaluate

public Object evaluate(EvaluationContext ec)
                throws EvaluationException
Evaluates this Expression by returning the logical negation of the sub-expression.

Specified by:
evaluate in class Expression
Parameters:
ec - The EvaluationContext in which this expression should be evaluated.
Returns:
The value of this UnaryMinusExpression.
Throws:
EvaluationException - If the sub-expression fails evaluation, or does not return a Boolean value.

getSubExpression

public Expression getSubExpression()
Gets the Expression which is being sign inverted by this one.

Returns:
The Expression which is being sign inverted by this one.

getSubExpressions

public List getSubExpressions()
Returns a list containing this UnaryMinusExpression and the expression to be sign inverted (in that order).

Specified by:
getSubExpressions in class Expression
Returns:
A list containing this UnaryMinusExpression and the expression to be sign inverted (in that order).

acceptVisitor

public void acceptVisitor(ExpressionVisitor visitor)
Description copied from class: Expression
Accepts an ExpressionVisitor.

Specified by:
acceptVisitor in class Expression

hashCode

public int hashCode()
Returns the hash code for this UnaryMinusExpression. The hash code of the UnaryMinusExpression is equal to the hash code of the value of this UnaryMinusExpression.

Overrides:
hashCode in class Object
Returns:
The hash code for this UnaryMinusExpression.

toString

public String toString()
Returns a String representation of this UnaryMinusExpression.

Overrides:
toString in class Object
Returns:
A String representation of this UnaryMinusExpression.

equals

public boolean equals(Object o)
Returns true if the specified object is equal to this one.

Overrides:
equals in class Object
Parameters:
o - The object to test for equality.
Returns:
true if the specified object is equal to this one, false otherwise.