Class ConstantNode
java.lang.Object
math.parser.ConstantNode
- All Implemented Interfaces:
Cloneable, ExpressionNode
Name: ConstantNode
Description: A constant value node
Date: 08/dic/06 Time: 15:35:24
- Version:
- 1.0
- Author:
- Bertoli Marco
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ExpressionNode[]An empty array with childrenprotected doubleValue of the constantstatic final String[]List of built-in constant namesprotected StringName of the constant.static final double[]List of built-in constant valuesFields inherited from interface ExpressionNode
CONSTANT_NODE, FUNCTION_NODE, OPERATOR_NODE, VARIABLE_NODE -
Constructor Summary
ConstructorsConstructorDescriptionConstantNode(double constant) Builds a constant nodeConstantNode(int pos) Builds a constant node, with an unique constantConstantNode(String name) Builds a constant node, with an unique constant -
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
-
CONSTANTS
List of built-in constant names -
VALUES
public static final double[] VALUESList of built-in constant values -
constant
protected double constantValue of the constant -
name
Name of the constant. Only if it is built-in -
children
An empty array with children
-
-
Constructor Details
-
ConstantNode
public ConstantNode(double constant) Builds a constant node- Parameters:
constant- constant to be put in node
-
ConstantNode
Builds a constant node, with an unique constant- Parameters:
name- name of the constant in the CONSTANTS array
-
ConstantNode
public ConstantNode(int pos) Builds a constant node, with an unique constant- Parameters:
pos- position of the constant in the CONSTANTS array- See Also:
-
-
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
-