public class TreeNode
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected java.util.ArrayList<java.lang.String> |
childNodeKeys
List of child node keys, in the correct order.
|
protected java.util.HashMap<java.lang.String,TreeNode> |
childNodes
List of nodes that branch from this node.
|
protected float |
count
Frequency count for anything, for this node's value.
|
protected java.lang.String |
name
A unique name or ID for the node
|
protected TreeNode |
parent
The parent TreeNode.
|
protected MetricDataset |
value
The specific value for this node
|
protected java.lang.String |
valueType
The type of value that this node supports
|
Constructor and Description |
---|
TreeNode(java.lang.String theValueType)
Create a new instance of TreeNode.
|
TreeNode(java.lang.String theValueType,
MetricDataset theValue)
Create a new instance of TreeNode.
|
TreeNode(java.lang.String theName,
java.lang.String theValueType)
Create a new instance of TreeNode.
|
TreeNode(java.lang.String theName,
java.lang.String theValueType,
MetricDataset theValue)
Create a new instance of TreeNode.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addChildNode(TreeNode childNode)
Add a child node to this node.
|
boolean |
addChildNode(TreeNode childNode,
int index)
Add a child node to this node.
|
void |
clearChildNodes()
Clear the child nodes of this node.
|
java.lang.Object |
clone()
Clone and return a copy of this object.
|
TreeNode |
getChildNode(java.lang.String nodeName)
Get the child node with the specified name.
|
TreeNode |
getChildNodeDeep(java.lang.String nodeName)
Get the child node at any sub-tree branch with the specified name.
|
java.util.ArrayList<java.lang.String> |
getChildNodeKeys()
Get the list of ordered child node keys.
|
java.util.HashMap<java.lang.String,TreeNode> |
getChildNodes()
Get the list of child nodes.
|
TreeNode |
getChildNodeValue(java.lang.Object theValue)
Return the child node with the specified value if it exists.
|
TreeNode |
getChildNodeValueDeep(java.lang.Object theValue)
Return the child node with the specified value anywhere in the tree if it exists.
|
float |
getCount()
Get the count value, frequency or something else.
|
java.lang.String |
getName()
Get the node id or name.
|
TreeNode |
getParent()
Get the parent tree node.
|
java.lang.Object |
getValue()
Get the actual node value, not the enclosing
MetricValue object. |
java.lang.String |
getValueType()
Get the node value type.
|
java.lang.String |
getValueTypeMD()
Get the metric dataset value type, which is set when the
MetricDataset is created. |
boolean |
hasChildNode(java.lang.String nodeName)
Return true if a child node with the specified name exists.
|
boolean |
hasChildNodeDeep(java.lang.String nodeName)
Return true if a child node at any sub-tree branch with the specified name exists.
|
boolean |
hasChildNodes()
Return true if this node has child nodes.
|
boolean |
hasChildNodeValue(java.lang.Object theValue)
Return true if a child node with the specified value exists.
|
boolean |
hasChildNodeValueDeep(java.lang.Object theValue)
Return true if a child node with the specified value exists.
|
boolean |
hasValue(java.lang.Object theValue)
Return true if the value of this node is the same as the value passed in.
|
boolean |
isLeaf()
Return true if a leaf node.
|
int |
maxDepth()
Get the maximum tree depth for any branch.
|
java.util.ArrayList<TreeNode> |
nodesAtLevel(int level)
Get a list of all nodes at a particular level in the tree, across all branches.
|
boolean |
removeChildNode(java.lang.String nodeName)
Remove the child node with the specified name.
|
void |
setChildNodes(java.util.ArrayList<java.lang.String> keyList,
java.util.HashMap<java.lang.String,TreeNode> thisChildNodes)
Set the full list of child nodes, replacing any existing list.
|
void |
setChildNodes(java.util.HashMap<java.lang.String,TreeNode> thisChildNodes)
Set the full list of child nodes, replacing any existing list.
|
void |
setCount(float thisCount)
Set the count value, frequency or something else.
|
void |
setParent(TreeNode theParent)
Set the node parent.
|
void |
setValue(MetricDataset theValue)
Set the node value.
|
java.lang.String |
toString()
Return a string-based description of the node branch.
|
protected java.lang.String |
toString(TreeNode rootNode,
java.lang.String indent,
java.util.ArrayList<java.lang.String> alreadySearched)
Return a string-based description of the node branch.
|
java.lang.String |
treeValueDeep()
Traverse this tree structure and add a description of all value elements that
are not null or empty.
|
protected java.lang.String name
protected java.lang.String valueType
protected MetricDataset value
protected float count
protected java.util.ArrayList<java.lang.String> childNodeKeys
protected java.util.HashMap<java.lang.String,TreeNode> childNodes
protected TreeNode parent
public TreeNode(java.lang.String theValueType) throws java.lang.Exception
theValueType
- the type of value that this node supports.java.lang.Exception
- any error.public TreeNode(java.lang.String theName, java.lang.String theValueType)
theName
- a unique name or ID for the node.theValueType
- the type of value that this node supports.public TreeNode(java.lang.String theValueType, MetricDataset theValue) throws java.lang.Exception
theValueType
- the type of value that this node supports.theValue
- the specific value for this node.java.lang.Exception
- any error.public TreeNode(java.lang.String theName, java.lang.String theValueType, MetricDataset theValue)
theName
- a unique name or ID for the node.theValueType
- the type of value that this node supports.theValue
- the specific value for this node.public boolean isLeaf()
public boolean hasChildNodes()
public boolean hasChildNode(java.lang.String nodeName)
nodeName
- the name of the node to check for.public boolean hasValue(java.lang.Object theValue) throws java.lang.Exception
SimpleMathCompare
.mathCompare
method is used to make an
equivalence comparison. A numerical or String value is evaluated as is.
Lists are compared across individual elements, where this list should contain the input list.theValue
- the node value to check for.java.lang.Exception
- any error.public boolean hasChildNodeValue(java.lang.Object theValue) throws java.lang.Exception
theValue
- the node value to check for.java.lang.Exception
- any error.public int maxDepth()
public java.util.ArrayList<TreeNode> nodesAtLevel(int level)
level
- the tree level, starting at 0, for this node.public java.lang.String treeValueDeep()
public boolean hasChildNodeDeep(java.lang.String nodeName) throws java.lang.Exception
nodeName
- the name of the node to check for.java.lang.Exception
- any error.public boolean hasChildNodeValueDeep(java.lang.Object theValue) throws java.lang.Exception
SimpleMathCompare
.mathCompare
method is used to make an
equivalence comparison. A numerical or String value is evaluated as is. Any other
type is converted to a String using EvaluateBase
.valueToString
and that is used instead.theValue
- the node value to check for.java.lang.Exception
- any error.public TreeNode getChildNodeDeep(java.lang.String nodeName) throws java.lang.Exception
nodeName
- the name of the node to check for.java.lang.Exception
- any error.public TreeNode getChildNodeValue(java.lang.Object theValue) throws java.lang.Exception
SimpleMathCompare
.mathCompare
method is used to make an
equivalence comparison. A numerical or String value is evaluated as is. Any other
type is converted to a String using EvaluateBase
.valueToString
and that is used instead.theValue
- the node value to check for.java.lang.Exception
- any error.public TreeNode getChildNodeValueDeep(java.lang.Object theValue) throws java.lang.Exception
SimpleMathCompare
.mathCompare
method is used to make an
equivalence comparison. A numerical or String value is evaluated as is. Any other
type is converted to a String using EvaluateBase
.valueToString
and that is used instead.theValue
- the value to match with.java.lang.Exception
- any error.public java.lang.String getName()
public java.lang.String getValueType()
public java.lang.String getValueTypeMD()
MetricDataset
is created.
This can be different to the node value type, if it stores node values in a list, for example.value.getValueType
.public void setCount(float thisCount)
thisCount
- value of count.public float getCount()
public void setValue(MetricDataset theValue)
theValue
- the node value. Of type valueType.public java.lang.Object getValue()
MetricValue
object.ArrayList
of values, or single value using value.getFirstValue()
, or null
for no value.public TreeNode getChildNode(java.lang.String nodeName)
nodeName
- the name of the child node to retrieve.public java.util.ArrayList<java.lang.String> getChildNodeKeys()
public boolean addChildNode(TreeNode childNode)
childNode
- the node to add.public boolean addChildNode(TreeNode childNode, int index)
childNode
- the node to add.index
- the position in the ordered list to add the node. If larger
than the list, add at the end.public boolean removeChildNode(java.lang.String nodeName)
nodeName
- the name of the node to remove.public void clearChildNodes()
public void setChildNodes(java.util.HashMap<java.lang.String,TreeNode> thisChildNodes)
thisChildNodes
- the list of child nodes.public void setChildNodes(java.util.ArrayList<java.lang.String> keyList, java.util.HashMap<java.lang.String,TreeNode> thisChildNodes)
keyList
- ordered list of keys. This is the ordering for the tree values.thisChildNodes
- the list of child nodes.public java.util.HashMap<java.lang.String,TreeNode> getChildNodes()
public void setParent(TreeNode theParent)
theParent
- the node's parent node.public TreeNode getParent()
public java.lang.String toString()
toString
in class java.lang.Object
protected java.lang.String toString(TreeNode rootNode, java.lang.String indent, java.util.ArrayList<java.lang.String> alreadySearched)
rootNode
- the root node to start from.indent
- amount to indent string by.alreadySearched
- list of nodes already searched, in case of cycling.public java.lang.Object clone()
clone
in class java.lang.Object