Venice 0.7beta

org.mov.parser.expression
Class AbstractExpression

java.lang.Object
  extended by org.mov.parser.expression.AbstractExpression
All Implemented Interfaces:
java.lang.Cloneable, Expression
Direct Known Subclasses:
BinaryExpression, ClauseExpression, QuaternaryExpression, TerminalExpression, TernaryExpression, UnaryExpression

public abstract class AbstractExpression
extends java.lang.Object
implements Expression

The abstract base class for all expressions in the Gondola language. This class implements the Expression interface and provides functions for managing an expression's child nodes. E.g. the expression 4+5 would consist of three nodes. The plus being the root node, which would have two child nodes of 4 and 5.

See Also:
Expression

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
AbstractExpression()
          Create a new expression.
AbstractExpression(int childCount)
          Create a new expression with the given number of children.
 
Method Summary
abstract  java.lang.Object clone()
           
 boolean equals(java.lang.Object object)
          Returns whether this expression tree and the given expression tree are equivalent.
 Expression getChild(int index)
          Return the child of this node at the given index.
 int getIndex(Expression child)
          Return the index of the given argument in the expression.
static java.text.NumberFormat getNumberFormat()
           
 Expression getParent()
          Get the parent of this node.
 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 over the node's children.
static double parseDouble(java.lang.String doubleText)
          Parses doubleText from a string to produce a double.
static int parseInt(java.lang.String intText)
          Parses intText from a string to produce an integer.
 void setChild(Expression child, int index)
          Set this expression's child to the given child.
 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.
static java.lang.Double valueOfDouble(java.lang.String doubleText)
          Parses doubleText from a string to produce a Double Object.
static java.lang.Integer valueOfInt(java.lang.String intText)
          Parses intText from a string to produce an Integer Object.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.mov.parser.Expression
checkType, evaluate, getChildCount, getType, toString
 

Constructor Detail

AbstractExpression

public AbstractExpression()
Create a new expression.


AbstractExpression

public AbstractExpression(int childCount)
Create a new expression with the given number of children.

Parameters:
childCount - the number of children in the expression.
Method Detail

getParent

public Expression getParent()
Get the parent of this node.

Specified by:
getParent in interface Expression
Returns:
the parent.

setParent

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

Specified by:
setParent in interface Expression
Parameters:
parent - the new parent.

getChild

public Expression getChild(int index)
Return the child of this node at the given index.

Specified by:
getChild in interface Expression
Parameters:
index - the argument index
Returns:
child at given index.

isRoot

public boolean isRoot()
Return whether this node is the root node. The root node has no parent.

Specified by:
isRoot in interface Expression
Returns:
TRUE iff this node is the root node.

setChild

public void setChild(Expression child,
                     int index)
Set this expression's child to the given child. The new child will be removed from its parent.

Specified by:
setChild in interface Expression
Parameters:
child - the new child.
index - the index of the new child.

simplify

public 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.

Specified by:
simplify in interface Expression

getIndex

public int getIndex(Expression child)
Return the index of the given argument in the expression. This method uses reference equality rather than using the equals method.

Specified by:
getIndex in interface Expression
Parameters:
child - the child expression to locate
Returns:
index of the child expression or -1 if it could not be found

parseDouble

public static double parseDouble(java.lang.String doubleText)
                          throws java.lang.NumberFormatException
Parses doubleText from a string to produce a double.

Parameters:
doubleText - the string to be parsed
Returns:
the parsed value
Throws:
java.lang.NumberFormatException

parseInt

public static int parseInt(java.lang.String intText)
                    throws java.lang.NumberFormatException
Parses intText from a string to produce an integer.

Parameters:
intText - the string to be parsed
Returns:
the parsed value
Throws:
java.lang.NumberFormatException

valueOfDouble

public static java.lang.Double valueOfDouble(java.lang.String doubleText)
                                      throws java.lang.NumberFormatException
Parses doubleText from a string to produce a Double Object.

Parameters:
doubleText - the string to be parsed
Returns:
the parsed value as Double Object
Throws:
java.lang.NumberFormatException

valueOfInt

public static java.lang.Integer valueOfInt(java.lang.String intText)
                                    throws java.lang.NumberFormatException
Parses intText from a string to produce an Integer Object.

Parameters:
intText - the string to be parsed
Returns:
the parsed value as Integer Object
Throws:
java.lang.NumberFormatException

getNumberFormat

public static java.text.NumberFormat getNumberFormat()

equals

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

Specified by:
equals in interface Expression
Overrides:
equals in class java.lang.Object
Parameters:
object - the other expression

hashCode

public 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.

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

size

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

Specified by:
size in interface Expression
Returns:
number of nodes or 1 if this is a terminal node

size

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

Specified by:
size in interface Expression
Returns:
number of nodes in the tree with the given type.

iterator

public java.util.Iterator iterator()
Return an iterator over the node's children.

Specified by:
iterator in interface Expression
Returns:
iterator.

clone

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

Venice 0.7beta