Package uk.co.cogitolearning.cogpar
Class AdditionExpressionNode
- java.lang.Object
-
- uk.co.cogitolearning.cogpar.SequenceExpressionNode
-
- uk.co.cogitolearning.cogpar.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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class uk.co.cogitolearning.cogpar.SequenceExpressionNode
SequenceExpressionNode.Term
-
-
Field Summary
-
Fields inherited from class uk.co.cogitolearning.cogpar.SequenceExpressionNode
terms
-
Fields inherited from interface uk.co.cogitolearning.cogpar.ExpressionNode
ADDITION_NODE, CONSTANT_NODE, EXPONENTIATION_NODE, FUNCTION_NODE, MULTIPLICATION_NODE, VARIABLE_NODE
-
-
Constructor Summary
Constructors Constructor Description AdditionExpressionNode(ExpressionNode node, boolean positive)Constructor to create an addition with the first term already added.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(ExpressionNodeVisitor visitor)Implementation of the visitor design pattern.intgetType()Returns the type of the node, in this case ExpressionNode.ADDITION_NODEdoublegetValue()Returns the value of the sub-expression that is rooted at this node.-
Methods inherited from class uk.co.cogitolearning.cogpar.SequenceExpressionNode
add
-
-
-
-
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 addedpositive- 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
-
-