com.discoversites.util.collections.tree.array
Class ArrayTreeNode<T>
java.lang.Object
com.discoversites.util.collections.tree.array.ArrayTreeNode<T>
- Type Parameters:
T
- The type of element to be stored in the ArrayTreeNode
- All Implemented Interfaces:
- TreeNode<T>, Serializable
- Direct Known Subclasses:
- ArrayTreeRoot
public class ArrayTreeNode<T>
- extends Object
- implements TreeNode<T>
Implementation of TreeNode
backed by an ArrayList
- Author:
- Mark
- See Also:
- Serialized Form
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ArrayTreeNode
protected ArrayTreeNode(TreeNode<T> parent)
- Parameters:
parent
- The parent ArrayTree
object that this node belongs to.
ArrayTreeNode
protected ArrayTreeNode(TreeNode<T> parent,
T element)
- Parameters:
parent
- The parent ArrayTree
object that this node belongs to.element
- The object to be stored as this node's element
ArrayTreeNode
protected ArrayTreeNode()
addElement
public TreeNode<T> addElement(T element)
- Specified by:
addElement
in interface TreeNode<T>
- Parameters:
element
- An element to be added as a child node to this node.
- Returns:
- The node that was created to store the element.
addNode
public void addNode(TreeNode<T> node)
- Specified by:
addNode
in interface TreeNode<T>
- Parameters:
node
- A node to be added as a child to this node.
addNode
public void addNode(TreeRoot<T> root)
- Specified by:
addNode
in interface TreeNode<T>
- Parameters:
root
- A node to be added as a child to this node.
getChildren
public Collection<TreeNode<T>> getChildren()
- Specified by:
getChildren
in interface TreeNode<T>
- Returns:
- The child nodes of this node.
getParent
public TreeNode<T> getParent()
- Specified by:
getParent
in interface TreeNode<T>
- Returns:
- The parent node of this node.
getRoot
public ArrayTreeRoot<T> getRoot()
- Specified by:
getRoot
in interface TreeNode<T>
- Returns:
- The root node of the tree this node belongs to.
addAll
public void addAll(Collection<TreeNode<T>> nodes)
- Specified by:
addAll
in interface TreeNode<T>
- Parameters:
nodes
- One or more nodes to be added as children to this node.
getElement
public T getElement()
- Specified by:
getElement
in interface TreeNode<T>
- Returns:
- The element stored in this node.
setElement
public void setElement(T element)
- Specified by:
setElement
in interface TreeNode<T>
- Parameters:
element
- An element to be stored in this node, replacing the current element if one exists.
removeNode
public void removeNode(TreeNode<T> node)
- Specified by:
removeNode
in interface TreeNode<T>
- Parameters:
node
- A child node of this node, that is to be removed from this node.
isLeaf
public boolean isLeaf()
- Specified by:
isLeaf
in interface TreeNode<T>
- Returns:
- True if this is a leaf node (i.e. it has no children), false otherwise.
isRoot
public boolean isRoot()
- Specified by:
isRoot
in interface TreeNode<T>
- Returns:
- True if this is a root node (i.e. it has no parents), false otherwise.
getDepth
public int getDepth()
- Specified by:
getDepth
in interface TreeNode<T>
- Returns:
- The depth (i.e. level) that this node occupies in it's parent
Tree
.
getSiblings
public Collection<TreeNode<T>> getSiblings()
- Specified by:
getSiblings
in interface TreeNode<T>
- Returns:
- The sibling nodes of this node.
getTree
public ArrayTree<T> getTree()
- Specified by:
getTree
in interface TreeNode<T>
- Returns:
- The
Tree
that this node belongs to.