Package com.singularsys.jep

# Class NodeFactory

java.lang.Object
com.singularsys.jep.NodeFactory

All Implemented Interfaces:
  `JepComponent`, `Serializable`

Direct Known Subclasses:
  `LineNumberingNodeFactory`

public class NodeFactory extends Object implements JepComponent
This class is used to create nodes of specified types. It can be sub-classed to change the nature of how nodes are constructed. Generally there are two methods for creating nodes, methods which take an existing node and methods which take the components.

Author:
  Rich Morris Created on 16-Nov-2003
See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected Evaluator`
  `ev`
  `protected Jep`
  `j`
  `protected VariableTable`
  `vt`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `NodeFactory()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ASTConstant`
  `buildConstantNode(Operator op, Node... children)`
  Creates a ASTConstant whose value of applying the operator to its arguments.
  `ASTConstant`
  `buildConstantNode(ASTConstant node)`
  Create an ASTConstant with same value as argument
  `ASTConstant`
  `buildConstantNode(PostfixMathCommandI pfmc, Node... children)`
  Creates a constant node whose result is the given function applied to the children.
  `ASTConstant`
  `buildConstantNode(Object value)`
  Creates an ASTConstant node with specified value.
  `ASTFunNode`
  `buildFunctionNode(ASTFunNode node, Node... arguments)`
  Builds a function with n arguments and same fun as specified in arguments.
  `ASTFunNode`
  `buildFunctionNode(String name, PostfixMathCommandI pfmc, Node... arguments)`
  Builds a function with n arguments.
  `ASTFunNode`
  `buildFunctionNode(String name, PostfixMathCommandI pfmc, List<Node> arguments)`
  Builds a function with arguments specified in a list.
  `ASTOpNode`
  `buildOperatorNode(Operator op, Node... arguments)`
  Builds an operator node with n arguments This method should be sub-classed.
  `ASTOpNode`
  `buildOperatorNode(Operator op, List<Node> arguments)`
  Builds an operator node with arguments specified in a list.
  `ASTOpNode`
  `buildUnfinishedOperatorNode(Operator op)`
  An unfinished node.
  `ASTVarNode`
  `buildVariableNode(ASTVarNode node)`
  creates a new ASTVarNode with the same name as argument.
  `ASTVarNode`
  `buildVariableNode(Variable var)`
  creates a new ASTVarNode with a given variable.
  `ASTVarNode`
  `buildVariableNode(String name)`
  Build a variable node when just the name is known.
  `ASTVarNode`
  `buildVariableNodeCheckUndeclared(String name)`
  Build a variable node checking for the undeclared status.
  `void`
  `copyChildren(Node node, Node... children)`
  Sets the children of node to be those specified in array.
  `void`
  `copyChildren(Node node, List<Node> children)`
  Sets the children of node to be those in the list.
  `JepComponent`
  `getLightWeightInstance()`
  Gets a light-weight instance suitable for using in multiple threads.
  `void`
  `init(Jep jep)`
  Initialize the component.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### ev

    protected transient Evaluator ev

  - ### vt

    protected transient VariableTable vt

  - ### j

    protected transient Jep j

- ## Constructor Details

  - ### NodeFactory

    public NodeFactory()

- ## Method Details

  - ### init

    public void init(Jep jep)
    Description copied from interface: `JepComponent`
    Initialize the component. This method is called whenever a component is added to Jep. Hence, it allows components to keep track of the other components they may rely on.
    Specified by:
      `init` in interface `JepComponent`
    Parameters:
      `jep` - the current Jep instance

  - ### copyChildren

    public void copyChildren(Node node, Node... children)
    Sets the children of node to be those specified in array.
    Parameters:
      `node` - the node whose children will be set.
      `children` - an array of nodes which will be the children of the node.

  - ### copyChildren

    public void copyChildren(Node node, List<Node> children)
    Sets the children of node to be those in the list.
    Parameters:
      `node` - the node whose children will be set.
      `children` - a list of nodes which will be the children of the node.
    Since:
      4.1

  - ### buildConstantNode

    public ASTConstant buildConstantNode(Object value) throws ParseException
    Creates an ASTConstant node with specified value. This method should be overwritten by subclasses.
    Throws:
      `ParseException`

  - ### buildConstantNode

    public ASTConstant buildConstantNode(ASTConstant node) throws ParseException
    Create an ASTConstant with same value as argument. *
    Throws:
      `ParseException`

  - ### buildConstantNode

    public ASTConstant buildConstantNode(PostfixMathCommandI pfmc, Node... children) throws ParseException
    Creates a constant node whose result is the given function applied to the children. This method replaces non varargs methods in Jep 3.4
    Parameters:
      `pfmc` - the function to apply
      `children` - the arguments to the function, each argument should be a constant node.
    Returns:
      a new constant node
    Throws:
      `ParseException`
    Since:
      3.5

  - ### buildConstantNode

    public ASTConstant buildConstantNode(Operator op, Node... children) throws ParseException
    Creates a ASTConstant whose value of applying the operator to its arguments.
    Throws:
      `ParseException`

  - ### buildVariableNode

    public ASTVarNode buildVariableNode(ASTVarNode node) throws ParseException
    creates a new ASTVarNode with the same name as argument.
    Throws:
      `ParseException`

  - ### buildVariableNode

    public ASTVarNode buildVariableNode(Variable var) throws ParseException
    creates a new ASTVarNode with a given variable. This method should be sub-classed
    Throws:
      `ParseException`

  - ### buildVariableNode

    public ASTVarNode buildVariableNode(String name) throws ParseException
    Build a variable node when just the name is known.
    Parameters:
      `name` - the name of the variable
    Returns:
      the node created
    Throws:
      `ParseException`

  - ### buildVariableNodeCheckUndeclared

    public ASTVarNode buildVariableNodeCheckUndeclared(String name) throws ParseException
    Build a variable node checking for the undeclared status.
    Parameters:
      `name` - name of the variable
    Returns:
      a new node
    Throws:
      `ParseException` - if undeclared variables are not allowed and the variable does not exist

  - ### buildOperatorNode

    public ASTOpNode buildOperatorNode(Operator op, Node... arguments) throws ParseException
    Builds an operator node with n arguments This method should be sub-classed. This varargs method replaces corresponding non varargs methods from Jep 3.4
    Parameters:
      `op` - the operator to use
      `arguments` - the arguments to the function.
    Returns:
      top Node of expression
    Throws:
      `ParseException`
    Since:
      3.5

  - ### buildOperatorNode

    public ASTOpNode buildOperatorNode(Operator op, List<Node> arguments) throws ParseException
    Builds an operator node with arguments specified in a list. This method is the same as `buildOperatorNode(Operator, Node...)` but takes a list of arguments instead of an array. This varargs method replaces corresponding non varargs methods from Jep 3.4
    Parameters:
      `op` - the operator to use
      `arguments` - the arguments to the function.
    Returns:
      top Node of expression
    Throws:
      `ParseException`
    Since:
      4.1

  - ### buildUnfinishedOperatorNode

    public ASTOpNode buildUnfinishedOperatorNode(Operator op)
    An unfinished node. Caller has responsibility for filling in the children.

  - ### buildFunctionNode

    public ASTFunNode buildFunctionNode(String name, PostfixMathCommandI pfmc, Node... arguments) throws ParseException
    Builds a function with n arguments. Subclasses should override this method.
    Parameters:
      `name` - of function.
      `pfmc` - PostfixMathCommand for function.
      `arguments` - the arguments to the function.
    Returns:
      top Node of expression
    Throws:
      `ParseException`

  - ### buildFunctionNode

    public ASTFunNode buildFunctionNode(String name, PostfixMathCommandI pfmc, List<Node> arguments) throws ParseException
    Builds a function with arguments specified in a list. This method is the same as `buildFunctionNode(String, PostfixMathCommandI, Node...)` but takes a list of arguments instead of an array. Subclasses should override this method.
    Parameters:
      `name` - of function.
      `pfmc` - PostfixMathCommand for function.
      `arguments` - the arguments to the function.
    Returns:
      top Node of expression
    Throws:
      `ParseException`

  - ### buildFunctionNode

    public ASTFunNode buildFunctionNode(ASTFunNode node, Node... arguments) throws ParseException
    Builds a function with n arguments and same fun as specified in arguments.
    Parameters:
      `node` - the properties (name and pfmc) of this node will be copied.
      `arguments` - the arguments to the function.
    Returns:
      top Node of expression
    Throws:
      `ParseException`

  - ### getLightWeightInstance

    public JepComponent getLightWeightInstance()
    Description copied from interface: `JepComponent`
    Gets a light-weight instance suitable for using in multiple threads.
    Specified by:
      `getLightWeightInstance` in interface `JepComponent`
    Returns:
      new NodeFactory()