org.entityfs.support.util
Class TreeNode<T>

java.lang.Object
  extended by org.entityfs.support.util.TreeNode<T>

public class TreeNode<T>
extends Object

This is a simple implementation of a node in a linked tree of objects. The node contains a value and an optional list of child nodes. This can be used to create simple object trees.

The tree node value cannot be modified after it has been created. New child entities can be added though.

Objects of this class are not thread safe.

Since:
1.0
Author:
Karl Gustafsson

Constructor Summary
TreeNode(T value)
          Create a new tree node.
 
Method Summary
 TreeNode<T> addChildNode(TreeNode<T> n)
          Add one child node.
 TreeNode<T> addChildNodes(Collection<? extends TreeNode<T>> c)
          Add a collection of child nodes.
 boolean equals(Object o)
           
 Set<TreeNode<T>> getChildNodes()
          Get the set of child nodes.
 T getValue()
          Get the tree node's value.
 int hashCode()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TreeNode

public TreeNode(T value)
         throws NullPointerException
Create a new tree node.

Parameters:
value - The node's value.
Throws:
NullPointerException - If value is null.
Method Detail

getValue

public T getValue()
Get the tree node's value.

Returns:
The tree node's value.

addChildNode

public TreeNode<T> addChildNode(TreeNode<T> n)
Add one child node.

Parameters:
n - A child node.
Returns:
this

addChildNodes

public TreeNode<T> addChildNodes(Collection<? extends TreeNode<T>> c)
Add a collection of child nodes.

Parameters:
c - A collection of child nodes.
Returns:
this

getChildNodes

public Set<TreeNode<T>> getChildNodes()
Get the set of child nodes.

Changes made to the set will modify the state of this object.

Returns:
The set of child nodes. Possibly empty, but never null.

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object