Class ConstantNode

java.lang.Object
math.parser.ConstantNode
All Implemented Interfaces:
Cloneable, ExpressionNode

public class ConstantNode extends Object implements ExpressionNode

Name: ConstantNode

Description: A constant value node

Date: 08/dic/06 Time: 15:35:24

Version:
1.0
Author:
Bertoli Marco
  • Field Details

    • CONSTANTS

      public static final String[] CONSTANTS
      List of built-in constant names
    • VALUES

      public static final double[] VALUES
      List of built-in constant values
    • constant

      protected double constant
      Value of the constant
    • name

      protected String name
      Name of the constant. Only if it is built-in
    • children

      protected ExpressionNode[] children
      An empty array with children
  • Constructor Details

    • ConstantNode

      public ConstantNode(double constant)
      Builds a constant node
      Parameters:
      constant - constant to be put in node
    • ConstantNode

      public ConstantNode(String name)
      Builds a constant node, with an unique constant
      Parameters:
      name - name of the constant in the CONSTANTS array
    • ConstantNode

      public ConstantNode(int pos)
      Builds a constant node, with an unique constant
      Parameters:
      pos - position of the constant in the CONSTANTS array
      See Also:
  • Method Details

    • count

      public int count()
      Description copied from interface: ExpressionNode
      Counts number of nodes in current subtree
      Specified by:
      count in interface ExpressionNode
      Returns:
      number of nodes (included root)
    • getDepth

      public int getDepth()
      Description copied from interface: ExpressionNode
      Returns depth of current subtree
      Specified by:
      getDepth in interface ExpressionNode
      Returns:
      depth of the tree
    • getSubtype

      public String getSubtype()
      Description copied from interface: ExpressionNode
      Returns more information on node type
      Specified by:
      getSubtype in interface ExpressionNode
      Returns:
      name of node function or operator symbol
    • getType

      public int getType()
      Description copied from interface: ExpressionNode
      Returns type of node
      Specified by:
      getType in interface ExpressionNode
      Returns:
      CONSTANT_NODE, VARIABLE_NODE, OPERATOR_NODE, FUNCTION_NODE
    • getValue

      public double getValue()
      Description copied from interface: ExpressionNode
      Returns value of target node
      Specified by:
      getValue in interface ExpressionNode
      Returns:
      value of node
    • setVariable

      public void setVariable(String name, double value)
      Description copied from interface: ExpressionNode
      Sets the value for a variable
      Specified by:
      setVariable in interface ExpressionNode
      Parameters:
      name - name of the variable to be set
      value - value for the variable
    • getChildrenNodes

      public ExpressionNode[] getChildrenNodes()
      Description copied from interface: ExpressionNode
      Returns children nodes of this node, ordered from leftmost to rightmost.
      Specified by:
      getChildrenNodes in interface ExpressionNode
      Returns:
      an array of children nodes. If node has no child, destination array has zero size.
    • clone

      public Object clone()
      Description copied from interface: ExpressionNode
      Clones current node
      Specified by:
      clone in interface ExpressionNode
      Overrides:
      clone in class Object
      Returns:
      deep copy of current node
    • toString

      public String toString()
      Description copied from interface: ExpressionNode
      Returns a string describing the entire tree
      Specified by:
      toString in interface ExpressionNode
      Overrides:
      toString in class Object
      Returns:
      string describing the entire tree