common
Class HashSetDiff

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet
          extended by common.HashSetDiff
All Implemented Interfaces:
SetDiff, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.Set

public class HashSetDiff
extends java.util.AbstractSet
implements SetDiff, java.lang.Cloneable

Implementation of SetDiff that uses hash sets to store additions and removals.


Constructor Summary
HashSetDiff(java.util.Set underlying)
          Creates a new HashSetDiff with the given underlying set.
HashSetDiff(java.util.Set underlying, boolean maintainOrder)
          Creates a new HashSetDiff with the given underlying set.
 
Method Summary
 boolean add(java.lang.Object o)
           
 void changeUnderlying()
          Changes the underlying set so it's equal to this set.
 void clearChanges()
          Changes this set so it's equal to the underlying set.
 java.lang.Object clone()
          Returns a shallow copy of this set diff, expressed relative to the same underlying set.
 boolean contains(java.lang.Object o)
           
protected  java.util.Set copySet(java.util.Set orig)
           
 java.util.Set getAdditions()
          Returns the set of objects that are in this set and not in the underlying set.
 java.util.Set getRemovals()
          Returns the set of objects that are in the underlying set but not in this set.
 java.util.Iterator iterator()
           
protected  java.util.Set newSet()
           
 boolean remove(java.lang.Object o)
           
 int size()
           
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, clear, containsAll, isEmpty, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, clear, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray, toArray
 

Constructor Detail

HashSetDiff

public HashSetDiff(java.util.Set underlying)
Creates a new HashSetDiff with the given underlying set.


HashSetDiff

public HashSetDiff(java.util.Set underlying,
                   boolean maintainOrder)
Creates a new HashSetDiff with the given underlying set. If maintainOrder is true, then this instance will use LinkedHashSets to keep the order of iteration predictable.

Method Detail

size

public int size()
Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.Set
Specified by:
size in class java.util.AbstractCollection

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection
Specified by:
contains in interface java.util.Set
Overrides:
contains in class java.util.AbstractCollection

iterator

public java.util.Iterator iterator()
Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in interface java.util.Set
Specified by:
iterator in class java.util.AbstractCollection

add

public boolean add(java.lang.Object o)
Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.Set
Overrides:
add in class java.util.AbstractCollection

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection
Specified by:
remove in interface java.util.Set
Overrides:
remove in class java.util.AbstractCollection

getAdditions

public java.util.Set getAdditions()
Description copied from interface: SetDiff
Returns the set of objects that are in this set and not in the underlying set.

Specified by:
getAdditions in interface SetDiff
Returns:
unmodifiable Set of objects

getRemovals

public java.util.Set getRemovals()
Description copied from interface: SetDiff
Returns the set of objects that are in the underlying set but not in this set.

Specified by:
getRemovals in interface SetDiff

changeUnderlying

public void changeUnderlying()
Description copied from interface: SetDiff
Changes the underlying set so it's equal to this set.

Specified by:
changeUnderlying in interface SetDiff

clearChanges

public void clearChanges()
Description copied from interface: SetDiff
Changes this set so it's equal to the underlying set.

Specified by:
clearChanges in interface SetDiff

clone

public java.lang.Object clone()
Returns a shallow copy of this set diff, expressed relative to the same underlying set.

Overrides:
clone in class java.lang.Object

newSet

protected java.util.Set newSet()

copySet

protected java.util.Set copySet(java.util.Set orig)