Package java.util
Class AbstractSet<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
- All Implemented Interfaces:
Iterable<E>,Collection<E>,Set<E>
- Direct Known Subclasses:
ConcurrentSkipListSet,CopyOnWriteArraySet,EnumSet,HashSet,TreeSet
public abstract class AbstractSet<E> extends AbstractCollection<E> implements Set<E>
An AbstractSet is an abstract implementation of the Set interface. This
implementation does not support adding. A subclass must implement the
abstract methods iterator() and size().
- Since:
- 1.2
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractSet()Constructs a new instance of this AbstractSet. -
Method Summary
Modifier and Type Method Description booleanequals(Object object)Compares the specified object to this Set and returns true if they are equal.inthashCode()Returns the hash code for this set.booleanremoveAll(Collection<?> collection)Removes all occurrences in this collection which are contained in the specified collection.Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, retainAll, size, toArray, toArray, toString
-
Constructor Details
-
AbstractSet
protected AbstractSet()Constructs a new instance of this AbstractSet.
-
-
Method Details
-
equals
Compares the specified object to this Set and returns true if they are equal. The object must be an instance of Set and contain the same objects.- Specified by:
equalsin interfaceCollection<E>- Specified by:
equalsin interfaceSet<E>- Overrides:
equalsin classObject- Parameters:
object- the object to compare with this set.- Returns:
trueif the specified object is equal to this set,falseotherwise- See Also:
hashCode()
-
hashCode
public int hashCode()Returns the hash code for this set. Two set which are equal must return the same value. This implementation calculates the hash code by adding each element's hash code.- Specified by:
hashCodein interfaceCollection<E>- Specified by:
hashCodein interfaceSet<E>- Overrides:
hashCodein classObject- Returns:
- the hash code of this set.
- See Also:
equals(java.lang.Object)
-
removeAll
Removes all occurrences in this collection which are contained in the specified collection.- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceSet<E>- Overrides:
removeAllin classAbstractCollection<E>- Parameters:
collection- the collection of objects to remove.- Returns:
trueif this collection was modified,falseotherwise.- Throws:
UnsupportedOperationException- if removing from this collection is not supported.
-