Class java.util.AbstractSet
java.lang.Object
|
+--java.util.AbstractCollection
|
+--java.util.AbstractSet
- Direct Known Subclasses:
- HashSet, TreeSet
- public abstract class AbstractSet
- extends AbstractCollection
- implements Set
This class provides a skeletal implementation of the Set interface to
minimize the effort required to implement this interface.
The process of implementing a Set by extending this class is identical to
that of implementing a Collection by extending AbstractCollection, except
that all of the methods and constructors in subclasses of this class must
obey the additional constraints imposed by the Set interface (for
instance, the add method must not permit addition of multiple intances of
an object to a Set).
Note that this class does not override any of the implementations
from abstractCollection. It merely adds implementations for
equals and hashCode.
- Since:
- JDK1.2
- See Also:
Collection
,
AbstractCollection
,
Set
Method Summary
|
boolean
|
equals(Object o)
Compares the specified Object with this Set for equality.
|
int
|
hashCode()
Returns the hash code value for this Set. |
Methods inherited from class java.util.AbstractCollection |
add
, addAll
, clear
, contains
, containsAll
, isEmpty
, iterator
, remove
, removeAll
, retainAll
, size
, toArray
, toArray
, toString
|
AbstractSet
public AbstractSet()
equals
public boolean equals(Object o)
- Compares the specified Object with this Set for equality.
Returns true if the given object is also a Set, the two Sets have the
same size, and every member of the given Set is contained in this Set.
This ensures that the equals method works properly accross different
implementations of the Set interface.
This implementation first checks if the specified Object is this Set;
if so it returns true. Then, it checks if the specified Object is
a Set whose size is identical to the size of this Set; if not, it
it returns false. If so, it returns
containsAll((Collection) o)
.
- Specified by:
- equals in interface Set
- Parameters:
o
- Object to be compared for equality with this Set.- Returns:
- true if the specified Object is equal to this Set.
- Overrides:
- equals in class Object
hashCode
public int hashCode()
- Returns the hash code value for this Set. The hash code of a Set
is defined to be the sum of the hashCodes of the elements
in the Set. This ensures that
s1.equals(s2)
implies that
s1.hashCode()==s2.hashCode()
for any two Sets
s1
and s2
, as required by the general
contract of Object.hashCode.
This implementation enumerates over the Set, calling hashCode
on each element in the Collection, and adding up the results.
- Specified by:
- hashCode in interface Set
- Overrides:
- hashCode in class Object
Submit a bug or feature
Submit comments/suggestions about new javadoc look
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.
This documentation was generated with a post-Beta4 version of Javadoc.