Package com.singularsys.jep
Class NodeFactory
java.lang.Object
com.singularsys.jep.NodeFactory
- All Implemented Interfaces:
JepComponent
,Serializable
- Direct Known Subclasses:
LineNumberingNodeFactory
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:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuildConstantNode
(Operator op, Node... children) Creates a ASTConstant whose value of applying the operator to its arguments.buildConstantNode
(ASTConstant node) Create an ASTConstant with same value as argument.buildConstantNode
(PostfixMathCommandI pfmc, Node... children) Creates a constant node whose result is the given function applied to the children.buildConstantNode
(Object value) Creates an ASTConstant node with specified value.buildFunctionNode
(ASTFunNode node, Node... arguments) Builds a function with n arguments and same fun as specified in arguments.buildFunctionNode
(String name, PostfixMathCommandI pfmc, Node... arguments) Builds a function with n arguments.buildOperatorNode
(Operator op, Node... arguments) Builds an operator node with n arguments This method should be sub-classed.An unfinished node.buildVariableNode
(ASTVarNode node) creates a new ASTVarNode with the same name as argument.creates a new ASTVarNode with a given variable.buildVariableNode
(String name) Build a variable node when just the name is known.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.Gets a light-weight instance suitable for using in multiple threads.void
Initialize the component.
-
Field Details
-
ev
-
vt
-
j
-
-
Constructor Details
-
NodeFactory
public NodeFactory()
-
-
Method Details
-
init
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 interfaceJepComponent
- Parameters:
jep
- the current Jep instance
-
copyChildren
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.
-
buildConstantNode
Creates an ASTConstant node with specified value. This method should be overwritten by subclasses.- Throws:
ParseException
-
buildConstantNode
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 applychildren
- the arguments to the function, each argument should be a constant node.- Returns:
- a new constant node
- Throws:
ParseException
- Since:
- 3.5
-
buildConstantNode
Creates a ASTConstant whose value of applying the operator to its arguments.- Throws:
ParseException
-
buildVariableNode
creates a new ASTVarNode with the same name as argument.- Throws:
ParseException
-
buildVariableNode
creates a new ASTVarNode with a given variable. This method should be sub-classed- Throws:
ParseException
-
buildVariableNode
Build a variable node when just the name is known.- Parameters:
name
- the name of the variable- Returns:
- the node created
- Throws:
ParseException
-
buildVariableNodeCheckUndeclared
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
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 usearguments
- the arguments to the function.- Returns:
- top Node of expression
- Throws:
ParseException
- Since:
- 3.5
-
buildUnfinishedOperatorNode
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
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
Description copied from interface:JepComponent
Gets a light-weight instance suitable for using in multiple threads.- Specified by:
getLightWeightInstance
in interfaceJepComponent
- Returns:
- new NodeFactory()
-