Class VariableNode
java.lang.Object
math.parser.VariableNode
- All Implemented Interfaces:
Cloneable, ExpressionNode
Name: VariableNode
Description: A node holding a double variable.
Date: 08/dic/06 Time: 15:56:59
- Version:
- 1.0
- Author:
- Bertoli Marco
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ExpressionNode[]An empty array with childrenprotected booleanTrue if variable was not initializedprotected StringName of the variableprotected doubleValue of the variableFields inherited from interface ExpressionNode
CONSTANT_NODE, FUNCTION_NODE, OPERATOR_NODE, VARIABLE_NODE -
Constructor Summary
ConstructorsConstructorDescriptionVariableNode(String name, boolean error) Creates a new variable node with given name. -
Method Summary
Modifier and TypeMethodDescriptionclone()Clones current nodeintcount()Counts number of nodes in current subtreeReturns children nodes of this node, ordered from leftmost to rightmost.intgetDepth()Returns depth of current subtreeReturns more information on node typeintgetType()Returns type of nodedoublegetValue()Returns value of target nodevoidsetVariable(String name, double value) Sets the value for a variabletoString()Returns a string describing the entire tree
-
Field Details
-
value
protected double valueValue of the variable -
error
protected boolean errorTrue if variable was not initialized -
name
Name of the variable -
children
An empty array with children
-
-
Constructor Details
-
VariableNode
Creates a new variable node with given name.- Parameters:
name- name of the variableerror- throws an exception if value is get but variable is not initialized. Otherwise 0.0 is returned.
-
-
Method Details
-
count
public int count()Description copied from interface:ExpressionNodeCounts number of nodes in current subtree- Specified by:
countin interfaceExpressionNode- Returns:
- number of nodes (included root)
-
getDepth
public int getDepth()Description copied from interface:ExpressionNodeReturns depth of current subtree- Specified by:
getDepthin interfaceExpressionNode- Returns:
- depth of the tree
-
getSubtype
Description copied from interface:ExpressionNodeReturns more information on node type- Specified by:
getSubtypein interfaceExpressionNode- Returns:
- name of node function or operator symbol
-
getType
public int getType()Description copied from interface:ExpressionNodeReturns type of node- Specified by:
getTypein interfaceExpressionNode- Returns:
- CONSTANT_NODE, VARIABLE_NODE, OPERATOR_NODE, FUNCTION_NODE
-
getValue
public double getValue()Description copied from interface:ExpressionNodeReturns value of target node- Specified by:
getValuein interfaceExpressionNode- Returns:
- value of node
-
setVariable
Description copied from interface:ExpressionNodeSets the value for a variable- Specified by:
setVariablein interfaceExpressionNode- Parameters:
name- name of the variable to be setvalue- value for the variable
-
getChildrenNodes
Description copied from interface:ExpressionNodeReturns children nodes of this node, ordered from leftmost to rightmost.- Specified by:
getChildrenNodesin interfaceExpressionNode- Returns:
- an array of children nodes. If node has no child, destination array has zero size.
-
clone
Description copied from interface:ExpressionNodeClones current node- Specified by:
clonein interfaceExpressionNode- Overrides:
clonein classObject- Returns:
- deep copy of current node
-
toString
Description copied from interface:ExpressionNodeReturns a string describing the entire tree- Specified by:
toStringin interfaceExpressionNode- Overrides:
toStringin classObject- Returns:
- string describing the entire tree
-