Package uk.co.cogitolearning.cogpar
Class ExponentiationExpressionNode
- java.lang.Object
-
- uk.co.cogitolearning.cogpar.ExponentiationExpressionNode
-
- All Implemented Interfaces:
ExpressionNode
public class ExponentiationExpressionNode extends Object implements ExpressionNode
An ExpressionNode that handles exponentiation. The node holds a base and an exponent and calulates base^exponent
-
-
Field Summary
-
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 ExponentiationExpressionNode(ExpressionNode base, ExpressionNode exponent)Construct the ExponentiationExpressionNode with base and exponent
-
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.EXPONENTIATION_NODEdoublegetValue()Returns the value of the sub-expression that is rooted at this node.
-
-
-
Constructor Detail
-
ExponentiationExpressionNode
public ExponentiationExpressionNode(ExpressionNode base, ExpressionNode exponent)
Construct the ExponentiationExpressionNode with base and exponent- Parameters:
base- the node containing the baseexponent- the node containing the exponent
-
-
Method Detail
-
getType
public int getType()
Returns the type of the node, in this case ExpressionNode.EXPONENTIATION_NODE- Specified by:
getTypein interfaceExpressionNode- Returns:
- type of the node
-
getValue
public double getValue()
Returns the value of the sub-expression that is rooted at this node. Calculates base^exponent- Specified by:
getValuein interfaceExpressionNode- 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 the base and the exponent.- Specified by:
acceptin interfaceExpressionNode- Parameters:
visitor- the visitor
-
-