Class AdditionExpressionNode

  • All Implemented Interfaces:
    ExpressionNode

    public class AdditionExpressionNode
    extends SequenceExpressionNode
    An ExpressionNode that handles additions and subtractions. The node can hold an arbitrary number of terms that are either added or subtracted from the sum.
    • Constructor Detail

      • AdditionExpressionNode

        public AdditionExpressionNode​(ExpressionNode node,
                                      boolean positive)
        Constructor to create an addition with the first term already added.
        Parameters:
        node - the term to be added
        positive - a flag indicating whether the term is added or subtracted
    • Method Detail

      • getType

        public int getType()
        Returns the type of the node, in this case ExpressionNode.ADDITION_NODE
        Returns:
        type of the node
      • getValue

        public double getValue()
        Returns the value of the sub-expression that is rooted at this node. All the terms are evaluated and added or subtracted from the total sum.
        Returns:
        value of expression
      • accept

        public void accept​(ExpressionNodeVisitor visitor)
        Implementation of the visitor design pattern. Calls visit on the visitor and then passes the visitor on to the accept method of all the terms in the sum.
        Parameters:
        visitor - the visitor