fabric.common.util
Class AbstractLongSet

java.lang.Object
  extended by fabric.common.util.AbstractLongCollection
      extended by fabric.common.util.AbstractLongSet
All Implemented Interfaces:
LongCollection, LongIterable, LongSet
Direct Known Subclasses:
LongHashSet

public abstract class AbstractLongSet
extends AbstractLongCollection
implements LongSet

An abstract implementation of Set to make it easier to create your own implementations. In order to create a Set, subclass AbstractSet and implement the same methods that are required for AbstractCollection (although these methods must of course meet the requirements that Set puts on them - specifically, no element may be in the set more than once). This class simply provides implementations of equals() and hashCode() to fulfil the requirements placed on them by the Set interface.

Since:
1.2
Author:
Original author unknown, Eric Blake (ebb9@email.byu.edu)
See Also:
LongCollection, AbstractLongCollection, LongSet, LongHashSet

Constructor Summary
protected AbstractLongSet()
          The main constructor, for use by subclasses.
 
Method Summary
 boolean equals(java.lang.Object o)
          Tests whether the given object is equal to this Set.
 int hashCode()
          Returns a hash code for this Set.
 boolean removeAll(LongCollection c)
          Removes from this set all elements in the given collection (optional operation).
 
Methods inherited from class fabric.common.util.AbstractLongCollection
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, retainAll, size, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface fabric.common.util.LongSet
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, retainAll, size, toArray, toArray
 

Constructor Detail

AbstractLongSet

protected AbstractLongSet()
The main constructor, for use by subclasses.

Method Detail

equals

public boolean equals(java.lang.Object o)
Tests whether the given object is equal to this Set. This implementation first checks whether this set is the given object, and returns true if so. Otherwise, if o is a Set and is the same size as this one, it returns the result of calling containsAll on the given Set. Otherwise, it returns false.

Specified by:
equals in interface LongCollection
Specified by:
equals in interface LongSet
Overrides:
equals in class java.lang.Object
Parameters:
o - the Object to be tested for equality with this Set
Returns:
true if the given object is equal to this Set

hashCode

public int hashCode()
Returns a hash code for this Set. The hash code of a Set is the sum of the hash codes of all its elements, except that the hash code of null is defined to be zero. This implementation obtains an Iterator over the Set, and sums the results.

Specified by:
hashCode in interface LongCollection
Specified by:
hashCode in interface LongSet
Overrides:
hashCode in class java.lang.Object
Returns:
a hash code for this Set
See Also:
LongSet.equals(Object)

removeAll

public boolean removeAll(LongCollection c)
Removes from this set all elements in the given collection (optional operation). This implementation uses size() to determine the smaller collection. Then, if this set is smaller, it iterates over the set, calling Iterator.remove if the collection contains the element. If this set is larger, it iterates over the collection, calling Set.remove for all elements in the collection. Note that this operation will fail if a remove methods is not supported.

Specified by:
removeAll in interface LongCollection
Specified by:
removeAll in interface LongSet
Overrides:
removeAll in class AbstractLongCollection
Parameters:
c - the collection of elements to remove
Returns:
true if the set was modified as a result
Throws:
java.lang.UnsupportedOperationException - if remove is not supported
java.lang.NullPointerException - if the collection is null
See Also:
AbstractLongCollection.remove(long), LongCollection.contains(long), LongIterator.remove()