Package com.singularsys.jep.walkers
Class ExpressionConsolidator
- java.lang.Object
-
- com.singularsys.jep.walkers.DoNothingVisitor
-
- com.singularsys.jep.walkers.DeepCopyVisitor
-
- com.singularsys.jep.walkers.ExpressionConsolidator
-
- All Implemented Interfaces:
JepComponent
,ParserVisitor
,java.io.Serializable
public class ExpressionConsolidator extends DeepCopyVisitor
Consolidates nested addition and multiplication to produce nary operators. For example (x+y)+z -> +(x,y,z)- Author:
- Richard Morris
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ExpressionConsolidator(Jep j)
Default constructor, Add and Multiply are consolidated.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(Operator op)
Adds an addition operator to be consolidated.Node
consolidate(Node node)
protected Node[]
consolidateChildren(Operator op, Node[] children)
Creates an array of Nodes, if the child is an ASTOpNode whose operator is op, then the children of that child will be added otherwise the child is added.java.util.List<Operator>
getOps()
The list of operators which are consolidatedjava.lang.Object
visit(ASTOpNode node, java.lang.Object data)
Visit a operator node.-
Methods inherited from class com.singularsys.jep.walkers.DeepCopyVisitor
deepCopy, visit, visit, visit
-
Methods inherited from class com.singularsys.jep.walkers.DoNothingVisitor
childrenHaveChanged, copyChildrenIfNeeded, getFunctionTable, getLightWeightInstance, getNodeFactory, getOperatorTable, getVariableTable, init, visit, visitChildren, visitNode
-
-
-
-
Field Detail
-
ops
protected java.util.List<Operator> ops
-
-
Constructor Detail
-
ExpressionConsolidator
public ExpressionConsolidator(Jep j)
Default constructor, Add and Multiply are consolidated.- Parameters:
j
-
-
-
Method Detail
-
consolidate
public Node consolidate(Node node) throws JepException
- Throws:
JepException
-
consolidateChildren
protected Node[] consolidateChildren(Operator op, Node[] children)
Creates an array of Nodes, if the child is an ASTOpNode whose operator is op, then the children of that child will be added otherwise the child is added.- Parameters:
op
-children
-- Returns:
- a new list of nodes
-
visit
public java.lang.Object visit(ASTOpNode node, java.lang.Object data) throws JepException
Description copied from class:DoNothingVisitor
Visit a operator node. Can be overridden by sub-classes.- Specified by:
visit
in interfaceParserVisitor
- Overrides:
visit
in classDeepCopyVisitor
- Throws:
JepException
-
add
public boolean add(Operator op)
Adds an addition operator to be consolidated.- Parameters:
op
- operator to use- Returns:
- true
-
getOps
public java.util.List<Operator> getOps()
The list of operators which are consolidated- Returns:
- the list
-
-