net.christopherschultz.evaluator
Class NegatedExpression

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

public class NegatedExpression
extends Expression

An Expression to perform a logical negation (i.e. NOT) of a sub-expression.

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

Constructor Summary
NegatedExpression(Expression subExpression)
          Creates a new NegatedExpression 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 negated by this one.
 List getSubExpressions()
          Returns a list containing this NegatedExpression and the expression to be negated (in that order).
 int hashCode()
          Returns the hash code for this NegatedExpression.
 String toString()
          Returns a String representation of this NegatedExpression.
 
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

NegatedExpression

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

Parameters:
subExpression - The expression whose result will be logically negated 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 NegatedExpression.
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 negated by this one.

Returns:
The Expression which is being negated by this one.

getSubExpressions

public List getSubExpressions()
Returns a list containing this NegatedExpression and the expression to be negated (in that order).

Specified by:
getSubExpressions in class Expression
Returns:
A list containing this NegatedExpression and the expression to be negated (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 NegatedExpression. The hash code of the NegatedExpression is equal to the hash code of the value of this NegatedExpression.

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

toString

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

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

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.