Venice 0.7beta

org.mov.parser.expression
Class ClauseExpression

java.lang.Object
  extended by org.mov.parser.expression.AbstractExpression
      extended by org.mov.parser.expression.ClauseExpression
All Implemented Interfaces:
java.lang.Cloneable, Expression

public class ClauseExpression
extends AbstractExpression

A clause is an ordered list of sub-expressions. Each sub-expression is executed serially. The value and type of the clause is the value and type of the last sub-expression in the clause.


Field Summary
 
Fields inherited from interface org.mov.parser.Expression
BOOLEAN_TYPE, FALSE, FLOAT_QUOTE_TYPE, FLOAT_TYPE, INTEGER_QUOTE_TYPE, INTEGER_TYPE, STRING_TYPE, TRUE, TRUE_LEVEL
 
Constructor Summary
ClauseExpression(java.util.List children)
          Create a new clause expression from the given list of expressions.
 
Method Summary
 int checkType()
          Perform type checking on the expression.
 java.lang.Object clone()
           
 double evaluate(Variables variables, QuoteBundle quoteBundle, Symbol symbol, int day)
          Evaluates the given expression and returns the result.
 int getChildCount()
          Return the number of children in the clause.
 int getType()
          Get the type of the expression.
 java.lang.String toString()
          Convert the given expression to a string.
static java.lang.String toString(Expression expression)
          A helper method to use when printing expressions that might be either sub-expressions or clause expressions.
 
Methods inherited from class org.mov.parser.expression.AbstractExpression
equals, getChild, getIndex, getNumberFormat, getParent, hashCode, isRoot, iterator, parseDouble, parseInt, setChild, setParent, simplify, size, size, valueOfDouble, valueOfInt
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClauseExpression

public ClauseExpression(java.util.List children)
Create a new clause expression from the given list of expressions.

Parameters:
children - list of expressions.
Method Detail

evaluate

public double evaluate(Variables variables,
                       QuoteBundle quoteBundle,
                       Symbol symbol,
                       int day)
                throws EvaluationException
Description copied from interface: Expression
Evaluates the given expression and returns the result.

Parameters:
variables - variable storage area for expression
quoteBundle - the quote bundle containing quote data to use
symbol - the current symbol
day - current date in cache fast access format
Returns:
the result of the expression
Throws:
EvaluationException - if the expression performs an illegal operation such as divide by zero.

toString

public static java.lang.String toString(Expression expression)
A helper method to use when printing expressions that might be either sub-expressions or clause expressions. For example the "if" expression, ignoring the else clause, could be printed in two ways:

  if(x) {
     statement1
     statement2
     ...
  }
 
or

  if(x)
     statement

 
Which one will depend on whether the expression is a clause or a sub-expression. This function analyses the given expression and makes sure it is printed correctly.

Parameters:
expression - the expression to print.
Returns:
string representation.

toString

public java.lang.String toString()
Description copied from interface: Expression
Convert the given expression to a string.

Specified by:
toString in interface Expression
Overrides:
toString in class java.lang.Object
Returns:
the string representation of the expression

checkType

public int checkType()
              throws TypeMismatchException
Description copied from interface: Expression
Perform type checking on the expression.

Returns:
the return type of the expression
Throws:
TypeMismatchException - if the expression has incorrect types

getType

public int getType()
Description copied from interface: Expression
Get the type of the expression.

Returns:
one of Expression.BOOLEAN_TYPE, Expression.FLOAT_TYPE, Expression.INTEGER_TYPE, Expression.FLOAT_QUOTE_TYPE or Expression.INTEGER_QUOTE_TYPE.

getChildCount

public int getChildCount()
Return the number of children in the clause. This is the number of sub-expressions.

Returns:
the number of sub-expressions.

clone

public java.lang.Object clone()
Specified by:
clone in interface Expression
Specified by:
clone in class AbstractExpression

Venice 0.7beta