com.graphbuilder.math
Class Expression

java.lang.Object
  extended bycom.graphbuilder.math.Expression
Direct Known Subclasses:
OpNode, TermNode, ValNode

public abstract class Expression
extends java.lang.Object

The class from which all nodes of an expression tree are descendents. Expressions can be evaluated using the eval method. Expressions that are or have FuncNodes or VarNodes as descendents must provide a VarMap or FuncMap respectively. Expressions that consist entirely of OpNodes and ValNodes do not require a VarMap or FuncMap. For Expressions that support children (OpNodes, FuncNodes), a child can only be accepted provided it currently has no parent, a cyclic reference is not formed, and it is non-null.


Field Summary
protected  Expression parent
           
 
Constructor Summary
Expression()
           
 
Method Summary
protected  void checkBeforeAccept(Expression x)
          Protected method used to verify that the specified expression can be included as a child expression of this node.
abstract  double eval(VarMap v, FuncMap f)
          Returns the result of evaluating the expression tree rooted at this node.
 java.lang.String[] getFunctionNames()
          Returns an array of exact length of the function names contained in the expression tree rooted at this node.
 Expression getParent()
          Returns the parent of this node.
 java.lang.String[] getVariableNames()
          Returns an array of exact length of the variable names contained in the expression tree rooted at this node.
 boolean isDescendent(Expression x)
          Returns true if this node is a descendent of the specified node, false otherwise.
 java.lang.String toString()
          Returns a string that represents the expression tree rooted at this node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parent

protected Expression parent
Constructor Detail

Expression

public Expression()
Method Detail

eval

public abstract double eval(VarMap v,
                            FuncMap f)
Returns the result of evaluating the expression tree rooted at this node.


isDescendent

public boolean isDescendent(Expression x)
Returns true if this node is a descendent of the specified node, false otherwise. By this methods definition, a node is a descendent of itself.


getParent

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


checkBeforeAccept

protected void checkBeforeAccept(Expression x)
Protected method used to verify that the specified expression can be included as a child expression of this node.

Throws:
java.lang.IllegalArgumentException - If the specified expression is not accepted.

getVariableNames

public java.lang.String[] getVariableNames()
Returns an array of exact length of the variable names contained in the expression tree rooted at this node.


getFunctionNames

public java.lang.String[] getFunctionNames()
Returns an array of exact length of the function names contained in the expression tree rooted at this node.


toString

public java.lang.String toString()
Returns a string that represents the expression tree rooted at this node.