net.sf.mmm.util.collection.base
Class AbstractTreeNode<NODE extends AbstractTreeNode<NODE>>

java.lang.Object
  extended by net.sf.mmm.util.collection.base.AbstractTreeNode<NODE>
Type Parameters:
NODE - is the generic type for self-references. Each sub-type of this class should specialize this type to itself.
All Implemented Interfaces:
TreeNode<NODE>

public abstract class AbstractTreeNode<NODE extends AbstractTreeNode<NODE>>
extends Object
implements TreeNode<NODE>

This is the abstract base implementation of the TreeNode interface.

Since:
1.0.2
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Field Summary
private  List<NODE> children
           
private  List<NODE> mutableChildList
           
private  NODE parent
           
 
Constructor Summary
AbstractTreeNode()
          The constructor.
AbstractTreeNode(ListFactory listFactory)
          The constructor.
AbstractTreeNode(NODE parent)
          The constructor.
AbstractTreeNode(NODE parent, ListFactory listFactory)
          The constructor.
 
Method Summary
protected  void addChild(NODE child)
          This method adds the given child to the children of this TreeNode.
 List<NODE> getChildren()
          This method gets the List containing all children of this TreeNode.
 NODE getParent()
          This method gets the parent of this TreeNode.
 boolean isAncestor(TreeNode<?> node)
          This method determines if this TreeNode is an ancestor of the given node.
 boolean isDescendant(TreeNode<?> node)
          This method determines if this TreeNode is a descendant of the given node.
protected  NODE removeChild(int index)
          This method removes the child from the children of this TreeNode at the given index.
protected  boolean removeChild(NODE child)
          This method removes the given child from the children of this TreeNode.
protected  void setParent(NODE parent)
          This method sets the parent of this TreeNode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mutableChildList

private final List<NODE extends AbstractTreeNode<NODE>> mutableChildList
See Also:
getChildren()

children

private final List<NODE extends AbstractTreeNode<NODE>> children
See Also:
getChildren()

parent

private NODE extends AbstractTreeNode<NODE> parent
See Also:
getParent()
Constructor Detail

AbstractTreeNode

public AbstractTreeNode()
The constructor.


AbstractTreeNode

public AbstractTreeNode(NODE parent)
The constructor.

Parameters:
parent - is the parent node.

AbstractTreeNode

public AbstractTreeNode(ListFactory listFactory)
The constructor.

Parameters:
listFactory - the factory used to create the internal List.

AbstractTreeNode

public AbstractTreeNode(NODE parent,
                        ListFactory listFactory)
The constructor.

Parameters:
parent - is the parent node.
listFactory - the factory used to create the internal List.
Method Detail

getParent

public NODE getParent()
This method gets the parent of this TreeNode.

Specified by:
getParent in interface TreeNode<NODE extends AbstractTreeNode<NODE>>
Returns:
the parent TreeNode or null if this is the root- TreeNode.

setParent

protected void setParent(NODE parent)
This method sets the parent of this TreeNode.

Parameters:
parent - is the parent to set. It may be null. However you should typically only call this method once with a non-null argument. It is still legal to re-arrange the tree-structure on existing TreeNodes.

getChildren

public List<NODE> getChildren()
This method gets the List containing all children of this TreeNode. The List may be empty - in such case we call this TreeNode a leaf. Each item of the returned List is called a child or child-node. It should return this TreeNode as parent.

Specified by:
getChildren in interface TreeNode<NODE extends AbstractTreeNode<NODE>>
Returns:
the List containing all children of this TreeNode.

addChild

protected void addChild(NODE child)
This method adds the given child to the children of this TreeNode.

Parameters:
child - is the child to add. It's parent has to be identical to this TreeNode.

removeChild

protected boolean removeChild(NODE child)
This method removes the given child from the children of this TreeNode.

Parameters:
child - is the child to remove.
Returns:
true if the given child was contained in this TreeNodes children and has been removed successfully, false otherwise.

removeChild

protected NODE removeChild(int index)
This method removes the child from the children of this TreeNode at the given index.

Parameters:
index - is index of the child to remove.
Returns:
the child that has actually been removed.

isAncestor

public boolean isAncestor(TreeNode<?> node)
This method determines if this TreeNode is an ancestor of the given node. In other words this method checks if this TreeNode is the direct or indirect parent of the given node.

Specified by:
isAncestor in interface TreeNode<NODE extends AbstractTreeNode<NODE>>
Parameters:
node - is the TreeNode to check (the potential descendant).
Returns:
true if this TreeNode is an ancestor of the given node.

isDescendant

public boolean isDescendant(TreeNode<?> node)
This method determines if this TreeNode is a descendant of the given node. In other words this method checks if this TreeNode is the direct or indirect child of the given node.

Specified by:
isDescendant in interface TreeNode<NODE extends AbstractTreeNode<NODE>>
Parameters:
node - is the TreeNode to check (the potential ancestor).
Returns:
true if this TreeNode is an descendant of the given node.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.