net.innig.collect
Class CollectionDiff<E>

java.lang.Object
  extended by net.innig.collect.CollectionDiff<E>
Direct Known Subclasses:
ListDiff

public class CollectionDiff<E>
extends java.lang.Object

Finds the difference between two Collections. This class returns the delta using Set, and therefore ignores duplicates and reordering.

CollectionDiff optionally creates internal copies of the input Collections. If you do not use this option, the results of CollectionDiff methods after a subsequent modification of the input collections are undefined.

Maturity: This is a mature API, and a stable implementation. It performs well in informal testing, but has not undergone methodical or real-world testing.
Plans: There are no current plans to expand or revise this class's functionality.

Version:
[Development version]
Author:
Paul Cantrell

Constructor Summary
CollectionDiff(java.util.Collection<? extends E> oldStuff, java.util.Collection<? extends E> newStuff)
          Prepares a comparison of two collections without creating an internal copy.
CollectionDiff(java.util.Collection<? extends E> oldStuff, java.util.Collection<? extends E> newStuff, boolean copy)
          Prepares a comparison of two collections, optionally creating an internal copy of the collections to allow subsequent modification of the collections being compared.
 
Method Summary
 boolean equals(java.lang.Object other)
          Returns true if the other object is a collection diff comparing equal collections.
 java.util.Set<E> getAdded()
          Returns the objects which are in newStuff but not oldStuff.
 java.util.Set<E> getRemoved()
          Returns the objects which are in oldStuff but not newStuff.
 java.util.Set<E> getSame()
          Returns the objects which are in both oldStuff and newStuff.
 int hashCode()
           
 boolean sameElements()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionDiff

public CollectionDiff(java.util.Collection<? extends E> oldStuff,
                      java.util.Collection<? extends E> newStuff)
Prepares a comparison of two collections without creating an internal copy.


CollectionDiff

public CollectionDiff(java.util.Collection<? extends E> oldStuff,
                      java.util.Collection<? extends E> newStuff,
                      boolean copy)
Prepares a comparison of two collections, optionally creating an internal copy of the collections to allow subsequent modification of the collections being compared.

Method Detail

getAdded

public java.util.Set<E> getAdded()
Returns the objects which are in newStuff but not oldStuff.


getRemoved

public java.util.Set<E> getRemoved()
Returns the objects which are in oldStuff but not newStuff.


getSame

public java.util.Set<E> getSame()
Returns the objects which are in both oldStuff and newStuff. Objects which have changed position in a list are considered "same".


sameElements

public boolean sameElements()

equals

public boolean equals(java.lang.Object other)
Returns true if the other object is a collection diff comparing equal collections.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object