[all packages] [package java.util] [class hierarchy] [index]

public abstract class java.util.AbstractSet<A>

(source file: AbstractSet.java)
java.lang.Object
   |
   +----java.util.AbstractCollection<A>
           |
           +----java.util.AbstractSet<A>

The pure class interface.
public abstract class AbstractSet<A>
  extends AbstractCollection<A>
  implements Set<A>
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.

See also:
Collection, AbstractCollection, Set

Constuctor Index

O AbstractSet()

Methods

O equals(Object)
Compares the specified Object with this Set for equality. Returns true if the given
O hashCode()
Returns the hash code value for this Set

Constructors

O AbstractSet
public AbstractSet();

Methods

O 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).

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

O 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.

Overrides:
hashCode in class Object


[all packages] [package java.util] [class hierarchy] [index]
java.util.AbstractSet.html