info.monitorenter.cpdetector.util.collections
Class TreeNodeUniqueChildren

java.lang.Object
  extended by info.monitorenter.cpdetector.util.collections.ITreeNode.DefaultTreeNode
      extended by info.monitorenter.cpdetector.util.collections.TreeNodeUniqueChildren
All Implemented Interfaces:
ITreeNode, Comparable

public class TreeNodeUniqueChildren
extends ITreeNode.DefaultTreeNode

An ITreeNode implementation, that does not allow equal m_children of one common parent node. Common elements in the path from an arbitrary node (seen as the root) to different leaves will share the same ITreeNode instances at runtime.

This behaviour may be used to create the smallest possible tree containing all given serialized paths.

Author:
Achim Westermann

Nested Class Summary
 
Nested classes/interfaces inherited from interface info.monitorenter.cpdetector.util.collections.ITreeNode
ITreeNode.DefaultTreeNode
 
Field Summary
 
Fields inherited from class info.monitorenter.cpdetector.util.collections.ITreeNode.DefaultTreeNode
m_children, m_userObject, marked
 
Fields inherited from interface info.monitorenter.cpdetector.util.collections.ITreeNode
ROOT
 
Constructor Summary
TreeNodeUniqueChildren()
           
TreeNodeUniqueChildren(Object userObject)
           
TreeNodeUniqueChildren(Object userObject, ITreeNode child)
           
TreeNodeUniqueChildren(Object userObject, ITreeNode[] children)
           
 
Method Summary
 boolean addChildNode(ITreeNode node)
          If the given argument is already a child node of this one (by the means of the equals method), it will replace the old node but gets the childs of the old node.
static void main(String[] args)
           Construction of a tree with the user Objects (java.lang.Integer) and use the toString() method.
 ITreeNode newInstance()
           Generic operations in default implementations may need to allocate new instances but have to choose the right type to support the provided invariants.
 
Methods inherited from class info.monitorenter.cpdetector.util.collections.ITreeNode.DefaultTreeNode
addChild, addChildNodes, addChildren, compareTo, contains, containsNode, equals, getAllChildren, getChildCount, getChilds, getParent, getPathFromRoot, getSubtreeCount, getUserObject, getUserObjectPathFromRoot, isLeaf, isMarked, isRoot, mark, remove, removeAllChildren, removeChild, setParent, setUserObject, toString, toStringInternal, unmark
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TreeNodeUniqueChildren

public TreeNodeUniqueChildren()

TreeNodeUniqueChildren

public TreeNodeUniqueChildren(Object userObject)
Parameters:
userObject -

TreeNodeUniqueChildren

public TreeNodeUniqueChildren(Object userObject,
                              ITreeNode child)
Parameters:
userObject -
child -

TreeNodeUniqueChildren

public TreeNodeUniqueChildren(Object userObject,
                              ITreeNode[] children)
Parameters:
userObject -
children -
Method Detail

addChildNode

public boolean addChildNode(ITreeNode node)
If the given argument is already a child node of this one (by the means of the equals method), it will replace the old node but gets the childs of the old node.

Specified by:
addChildNode in interface ITreeNode
Overrides:
addChildNode in class ITreeNode.DefaultTreeNode
Parameters:
node - the node to add as child.
Returns:
True, if the operation was succesful: For example some implementations (e.g. with support for unique user Objects in childs on the same level with the same parent node) may dissallow duplicate child nodes.
See Also:
ITreeNode.addChildNode(ITreeNode)

main

public static void main(String[] args)
                 throws Exception

Construction of a tree with the user Objects (java.lang.Integer) and use the toString() method.

 
 
              0
             /|\
            / | \
           1  2  1
          / \    |\
         /   \   | \
        4     5  6  7
                /|\
               / | \
              8  9  10
 
  
As only unique nodes are supported, the paths have to be flattended to:
 
              0
             / \
            /   \
           1     2
          /|\
         / | \
        /  | |\
       /   | | \
      4    5 6  7
            /|\
           / | \
          8  9  10
 
  

Throws:
Exception

newInstance

public ITreeNode newInstance()
Description copied from interface: ITreeNode

Generic operations in default implementations may need to allocate new instances but have to choose the right type to support the provided invariants.

If you provide a subclass that has invariants you should overload this.

Specified by:
newInstance in interface ITreeNode
Overrides:
newInstance in class ITreeNode.DefaultTreeNode
Returns:
A new allocated instance of the concrete impelementation.


Copyleft ㊢ 2003-2004 MPL 1.1, All Rights Footloose.