Class FunctionNode

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

public class FunctionNode extends Object implements ExpressionNode

Name: FunctionNode

Description: This node is used to evaluate every kind of function with a single parameter, like abs(...) or sin(...)

Date: 08/dic/06 Time: 16:31:14

Version:
1.0
Author:
Bertoli Marco
  • Field Details

    • FUNCTIONS

      public static final String[] FUNCTIONS
      List of supported functions
    • child

      protected ExpressionNode child
      Child node
    • function

      protected int function
      Function of this node
    • children

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

    • FunctionNode

      public FunctionNode(ExpressionNode child, int function)
      Creates a function node.
      Parameters:
      child - child node of this node
      function - function to be evaluated. This is the index in FUNCTIONS array
      See Also:
    • FunctionNode

      public FunctionNode(ExpressionNode child, String function) throws IllegalArgumentException
      Creates a function node.
      Parameters:
      child - child node of this node
      function - name of function to be evaluated.
      Throws:
      IllegalArgumentException - if function is unsupported
  • 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
    • setParser

      public void setParser(Parser parser)