Venice 0.7beta

org.mov.parser
Interface Expression

All Superinterfaces:
java.lang.Cloneable
All Known Implementing Classes:
AbsExpression, AbstractExpression, AddExpression, AndExpression, ArithmeticExpression, AvgExpression, BBLExpression, BBUExpression, BinaryExpression, ClauseExpression, ComparisionExpression, CorrExpression, CosineExpression, DayExpression, DayOfWeekExpression, DayOfYearExpression, DefineVariableExpression, DivideExpression, EMAExpression, EqualThanExpression, ExponentialExpression, ForExpression, GetVariableExpression, GreaterThanEqualExpression, GreaterThanExpression, IfExpression, LagExpression, LessThanEqualExpression, LessThanExpression, LogarithmExpression, LogicExpression, MACDExpression, MaxExpression, MinExpression, MomentumExpression, MonthExpression, MultiplyExpression, NotEqualExpression, NotExpression, NumberExpression, OBVExpression, OrExpression, PercentExpression, QuaternaryExpression, QuoteExpression, RSIExpression, SetVariableExpression, SineExpression, SqrtExpression, StandardDeviationExpression, StringExpression, SubtractExpression, SumExpression, TerminalExpression, TernaryExpression, TrendExpression, UnaryExpression, WhileExpression, YearExpression

public interface Expression
extends java.lang.Cloneable

Representation of a composite executable parse tree. Any expression in the Gondola language is parsed into a composite structure built upon this class. This class therefore represents an executable expression.

Any single object of this type could represent a terminal expression that is a number such as "5", a unary expression such as "not(X)", a binary expression such as "X and Y" or a ternary expression. The arguments labelled above as X and Y would be represented by separate Expression classes. Those classes would however be contained by this class.


Field Summary
static int BOOLEAN_TYPE
          A boolean type that can be either TRUE or FALSE.
static double FALSE
          Value of FALSE
static int FLOAT_QUOTE_TYPE
          Represents a stock float quote type: open, close, low, high
static int FLOAT_TYPE
          A float type that can contain any number.
static int INTEGER_QUOTE_TYPE
          Represents a stock integer quote type: volume
static int INTEGER_TYPE
          An integer type that can contain any integer number.
static int STRING_TYPE
          Represents a string type that can containy any string.
static double TRUE
          Value of TRUE
static double TRUE_LEVEL
          Threshold level where a number is registered as TRUE
 
Method Summary
 int checkType()
          Perform type checking on the expression.
 java.lang.Object clone()
           
 boolean equals(java.lang.Object object)
          Returns whether this expression tree and the given expression tree are equivalent.
 double evaluate(Variables variables, QuoteBundle quoteBundle, Symbol symbol, int day)
          Evaluates the given expression and returns the result.
 Expression getChild(int index)
          Return the given argument.
 int getChildCount()
          Return the number of arguments of this expression.
 int getIndex(Expression expression)
          Return the index of the given argument in the expression.
 Expression getParent()
          Return the parent of this node.
 int getType()
          Get the type of the expression.
 int hashCode()
          If you override the equals(java.lang.Object) method then you should override this method.
 boolean isRoot()
          Return whether this node is the root node.
 java.util.Iterator iterator()
          Return an iterator to iterate over all the nodes in this expression's tree.
 void setChild(Expression child, int index)
          Set the argument.
 void setParent(Expression parent)
          Set the parent of this node.
 Expression simplify()
          Perform simplifications and optimisations on the expression tree.
 int size()
          Count the number of nodes in the tree.
 int size(int type)
          Count the number of nodes in the tree with the given type.
 java.lang.String toString()
          Convert the given expression to a string.
 

Field Detail

BOOLEAN_TYPE

static final int BOOLEAN_TYPE
A boolean type that can be either TRUE or FALSE.

See Also:
Constant Field Values

FLOAT_TYPE

static final int FLOAT_TYPE
A float type that can contain any number.

See Also:
Constant Field Values

INTEGER_TYPE

static final int INTEGER_TYPE
An integer type that can contain any integer number.

See Also:
Constant Field Values

FLOAT_QUOTE_TYPE

static final int FLOAT_QUOTE_TYPE
Represents a stock float quote type: open, close, low, high

See Also:
Constant Field Values

INTEGER_QUOTE_TYPE

static final int INTEGER_QUOTE_TYPE
Represents a stock integer quote type: volume

See Also:
Constant Field Values

STRING_TYPE

static final int STRING_TYPE
Represents a string type that can containy any string.

See Also:
Constant Field Values

TRUE_LEVEL

static final double TRUE_LEVEL
Threshold level where a number is registered as TRUE

See Also:
Constant Field Values

TRUE

static final double TRUE
Value of TRUE

See Also:
Constant Field Values

FALSE

static final double FALSE
Value of FALSE

See Also:
Constant Field Values
Method Detail

evaluate

double evaluate(Variables variables,
                QuoteBundle quoteBundle,
                Symbol symbol,
                int day)
                throws EvaluationException
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

java.lang.String toString()
Convert the given expression to a string.

Overrides:
toString in class java.lang.Object
Returns:
the string representation of the expression

checkType

int checkType()
              throws TypeMismatchException
Perform type checking on the expression.

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

getType

int getType()
Get the type of the expression.

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

getChildCount

int getChildCount()
Return the number of arguments of this expression.

Returns:
the number of arguments

getParent

Expression getParent()
Return the parent of this node.

Returns:
the parent.

setParent

void setParent(Expression parent)
Set the parent of this node.

Parameters:
parent - the parent.

clone

java.lang.Object clone()

isRoot

boolean isRoot()
Return whether this node is the root node.

Returns:
TRUE if this node has no parent.

iterator

java.util.Iterator iterator()
Return an iterator to iterate over all the nodes in this expression's tree.

Returns:
iterator.

getChild

Expression getChild(int index)
Return the given argument.

Parameters:
index - the argument index
Returns:
the argument

setChild

void setChild(Expression child,
              int index)
Set the argument.

Parameters:
child - new argument expression
index - index of the argument expression

simplify

Expression simplify()
Perform simplifications and optimisations on the expression tree. For example, if the expression tree was a and true then the expression tree would be simplified to a.


getIndex

int getIndex(Expression expression)
Return the index of the given argument in the expression. We override this method because we use "==" to denote equality, not "equals" as the former would return the first argument with the same expression not necessarily the actual expression instance desired.

Parameters:
expression - the child expression to locate
Returns:
index of the child expression or -1 if it could not be found

equals

boolean equals(java.lang.Object object)
Returns whether this expression tree and the given expression tree are equivalent.

Overrides:
equals in class java.lang.Object
Parameters:
object - the other expression

hashCode

int hashCode()
If you override the equals(java.lang.Object) method then you should override this method. It provides a very basic hash code function.

Overrides:
hashCode in class java.lang.Object
Returns:
a poor hash code of the tree

size

int size()
Count the number of nodes in the tree.

Returns:
number of nodes or 1 if this is a terminal node

size

int size(int type)
Count the number of nodes in the tree with the given type.

Returns:
number of nodes in the tree with the given type.

Venice 0.7beta