Class ExpressionConsolidator

All Implemented Interfaces:
JepComponent, ParserVisitor, 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:
  • Field Details

  • Constructor Details

    • ExpressionConsolidator

      public ExpressionConsolidator(Jep j)
      Default constructor, Add and Multiply are consolidated.
      Parameters:
      j -
  • Method Details

    • 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 Object visit(ASTOpNode node, Object data) throws JepException
      Description copied from class: DoNothingVisitor
      Visit an operator node. Can be overridden by subclasses.
      Specified by:
      visit in interface ParserVisitor
      Overrides:
      visit in class DeepCopyVisitor
      Throws:
      JepException
    • add

      public boolean add(Operator op)
      Adds an addition operator to be consolidated.
      Parameters:
      op - operator to use
      Returns:
      true
    • getOps

      public List<Operator> getOps()
      The list of operators which are consolidated
      Returns:
      the list