net.christopherschultz.evaluator
Class ConstantExpression

java.lang.Object
  extended by net.christopherschultz.evaluator.Expression
      extended by net.christopherschultz.evaluator.ConstantExpression
Direct Known Subclasses:
IdentifierExpression

public class ConstantExpression
extends Expression

An Expression which represents a fixed value (a constant).

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

Constructor Summary
ConstantExpression(Object value)
          Creates a new ConstantExpression with the given value.
 
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 its constant value.
 List getSubExpressions()
          Returns a list containing a single element: this ConstantExpression.
 Object getValue()
          Gets the value of this constant Expression.
 int hashCode()
          Returns the hash code for this ConstantExpression.
 String toString()
          Returns a String representation of this Expression.
 
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

ConstantExpression

public ConstantExpression(Object value)
Creates a new ConstantExpression with the given value.

Parameters:
value - The value of the new ConstantExpressions.
Throws:
IllegalArgumentException - If the value is null.
Method Detail

evaluate

public Object evaluate(EvaluationContext ec)
                throws EvaluationException
Evaluates this Expression by returning its constant value.

Specified by:
evaluate in class Expression
Parameters:
ec - The EvaluationContext in which this expression should be evaluated.
Returns:
The value of this constant Expression.
Throws:
EvaluationException - If there is an error evaluating this Expression.

getSubExpressions

public List getSubExpressions()
Returns a list containing a single element: this ConstantExpression.

Specified by:
getSubExpressions in class Expression
Returns:
An immutable list containing this ConstantExpression.

getValue

public Object getValue()
Gets the value of this constant Expression.

Returns:
The value of this constant Expression.

hashCode

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

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

toString

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

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

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.

acceptVisitor

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

Specified by:
acceptVisitor in class Expression