Eidola home

org.eidola.util
Class CollectionDiff

java.lang.Object
  |
  +--org.eidola.util.CollectionDiff
Direct Known Subclasses:
ListDiff

public class CollectionDiff
extends 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.

Version:
[Development version]
Author:
Paul Cantrell

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

Constructor Detail

CollectionDiff

public CollectionDiff(Collection oldStuff,
                      Collection newStuff)
Prepares a comparison of two collections without creating an internal copy.

CollectionDiff

public CollectionDiff(Collection oldStuff,
                      Collection newStuff,
                      boolean copy)
Prepares a comparison of two collections, optionally creating an internal copy of the collections to allow subsequent modification.
Method Detail

getAdded

public Set getAdded()
Returns the objects which are in newStuff but not oldStuff.

getRemoved

public Set getRemoved()
Returns the objects which are in oldStuff but not newStuff.

getSame

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

equals

public boolean equals(Object other)
Returns true if the other object is a collection diff comparing equal collections.
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

Eidola home