Class Expression

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

public abstract class Expression extends 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 Details

  • Constructor Details

    • Expression

      public Expression()
  • Method Details

    • 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. Returns null if this node is the root node of an expression-tree.
    • 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. An expression cannot be included as a child if it is null, it currently has a parent, or a cyclic reference would be formed.
      Throws:
      IllegalArgumentException - If the specified expression is not accepted.
    • getVariableNames

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

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

      private String[] getTermNames(boolean varNames)
    • getTermNames

      private static void getTermNames(Expression x, Bag b, boolean varNames)
    • toString

      public String toString()
      Returns a string that represents the expression tree rooted at this node.
      Overrides:
      toString in class Object
    • toString

      private static void toString(Expression x, StringBuffer sb)