Package uk.co.cogitolearning.cogpar
Class VariableExpressionNode
- java.lang.Object
-
- uk.co.cogitolearning.cogpar.VariableExpressionNode
-
- All Implemented Interfaces:
ExpressionNode
public class VariableExpressionNode extends Object implements ExpressionNode
An ExpressionNode that stores a named variable
-
-
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 VariableExpressionNode(String name)Construct with the name of the variable.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(ExpressionNodeVisitor visitor)Implementation of the visitor design pattern.StringgetName()intgetType()Returns the type of the node, in this case ExpressionNode.VARIABLE_NODEdoublegetValue()Returns the value of the variable but throws an exception if the value has not been setvoidsetValue(double value)Sets the value of the variable
-
-
-
Constructor Detail
-
VariableExpressionNode
public VariableExpressionNode(String name)
Construct with the name of the variable.- Parameters:
name- the name of the variable
-
-
Method Detail
-
getName
public String getName()
- Returns:
- the name of the variable
-
getType
public int getType()
Returns the type of the node, in this case ExpressionNode.VARIABLE_NODE- Specified by:
getTypein interfaceExpressionNode- Returns:
- type of the node
-
getValue
public double getValue()
Returns the value of the variable but throws an exception if the value has not been set- Specified by:
getValuein interfaceExpressionNode- Returns:
- value of expression
-
setValue
public void setValue(double value)
Sets the value of the variable- Parameters:
value- the value of the variable
-
accept
public void accept(ExpressionNodeVisitor visitor)
Implementation of the visitor design pattern. Calls visit on the visitor.- Specified by:
acceptin interfaceExpressionNode- Parameters:
visitor- the visitor
-
-