de.unkrig.commons.util
Class TreeComparator<N extends TreeComparator.Node<N>,EX extends java.lang.Exception>

java.lang.Object
  extended by de.unkrig.commons.util.TreeComparator<N,EX>
Type Parameters:
N - The node type
EX - The exception that the abstract methods may throw

public abstract class TreeComparator<N extends TreeComparator.Node<N>,EX extends java.lang.Exception>
extends java.lang.Object

Recursively compares two trees of nodes. Non-leaf nodes have a SortedSet of keys to child nodes.

See Also:
compare(Node, Node)

Nested Class Summary
static interface TreeComparator.Node<N extends TreeComparator.Node<N>>
          The superinterface for leaf nodes and non-leaf nodes.
 
Constructor Summary
TreeComparator()
           
 
Method Summary
 void compare(N node1, N node2)
          If both nodes are non-leaf nodes, nodeDeleted(N) and nodeAdded(N) are called for each child that exists only in the first resp. only in the second child set.
protected abstract  void leafNodeChangedToNonLeafNode(N node1, N node2)
          This abstract method is invoked by compare(Node, Node) for every node that is a leaf node under node1 and a non-leaf node under node2.
protected abstract  void leafNodeRemains(N node1, N node2)
          This abstract method is invoked by compare(Node, Node) for every leaf node that exists under node1 and under node2.
protected abstract  void nodeAdded(N node)
          This abstract method is invoked by compare(Node, Node) for every node that does not exist under node1, but under node2.
protected abstract  void nodeDeleted(N node)
          This abstract method is invoked by compare(Node, Node) for every node that exists under node1, but not under node2.
protected abstract  void nonLeafNodeChangedToLeafNode(N node1, N node2)
          This abstract method is invoked by compare(Node, Node) for every node that is a non-leaf node under node1 and a leaf node under node2.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeComparator

public TreeComparator()
Method Detail

compare

public void compare(N node1,
                    N node2)
             throws EX extends java.lang.Exception
If both nodes are non-leaf nodes, nodeDeleted(N) and nodeAdded(N) are called for each child that exists only in the first resp. only in the second child set. For each child that exists in both child sets, this method is invoked recursively.

Otherwise, if one of the nodes is a leaf node and the other is not, leafNodeChangedToNonLeafNode(N, N) or nonLeafNodeChangedToLeafNode(N, N) is invoked.

Otherwise, both nodes are leaf nodes, and leafNodeRemains(N, N) is invoked.

Throws:
EX extends java.lang.Exception

nodeAdded

protected abstract void nodeAdded(N node)
                           throws EX extends java.lang.Exception
This abstract method is invoked by compare(Node, Node) for every node that does not exist under node1, but under node2.

Throws:
EX extends java.lang.Exception

nodeDeleted

protected abstract void nodeDeleted(N node)
                             throws EX extends java.lang.Exception
This abstract method is invoked by compare(Node, Node) for every node that exists under node1, but not under node2.

Throws:
EX extends java.lang.Exception

nonLeafNodeChangedToLeafNode

protected abstract void nonLeafNodeChangedToLeafNode(N node1,
                                                     N node2)
                                              throws EX extends java.lang.Exception
This abstract method is invoked by compare(Node, Node) for every node that is a non-leaf node under node1 and a leaf node under node2.

Throws:
EX extends java.lang.Exception

leafNodeChangedToNonLeafNode

protected abstract void leafNodeChangedToNonLeafNode(N node1,
                                                     N node2)
                                              throws EX extends java.lang.Exception
This abstract method is invoked by compare(Node, Node) for every node that is a leaf node under node1 and a non-leaf node under node2.

Throws:
EX extends java.lang.Exception

leafNodeRemains

protected abstract void leafNodeRemains(N node1,
                                        N node2)
                                 throws EX extends java.lang.Exception
This abstract method is invoked by compare(Node, Node) for every leaf node that exists under node1 and under node2.

Throws:
EX extends java.lang.Exception