FileDocCategorySizeDatePackage
AbstractSet.javaAPI DocAndroid 1.5 API3895Wed May 06 22:41:04 BST 2009java.util

AbstractSet

public abstract class AbstractSet extends AbstractCollection implements Set
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
Android 1.0

Fields Summary
Constructors Summary
protected AbstractSet()
Constructs a new instance of this AbstractSet.

since
Android 1.0

        super();
    
Methods Summary
public booleanequals(java.lang.Object object)
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.

param
object the object to compare with this set.
return
{@code true} if the specified object is equal to this set, {@code false} otherwise
see
#hashCode
since
Android 1.0

        if (this == object) {
            return true;
        }
        if (object instanceof Set) {
            Set<?> s = (Set<?>) object;
            // BEGIN android-changed
            // copied from a newer version of harmony
            try {
                return size() == s.size() && containsAll(s);
            } catch (ClassCastException cce) {
                return false;
            }
            // END android-changed
        }
        return false;
    
public inthashCode()
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.

return
the hash code of this set.
see
#equals
since
Android 1.0

        int result = 0;
        Iterator<?> it = iterator();
        while (it.hasNext()) {
            Object next = it.next();
            result += next == null ? 0 : next.hashCode();
        }
        return result;
    
public booleanremoveAll(java.util.Collection collection)
Removes all occurrences in this collection which are contained in the specified collection.

param
collection the collection of objects to remove.
return
{@code true} if this collection was modified, {@code false} otherwise.
exception
UnsupportedOperationException when removing from this collection is not supported.
since
Android 1.0

        boolean result = false;
        if (size() <= collection.size()) {
            Iterator<?> it = iterator();
            while (it.hasNext()) {
                if (collection.contains(it.next())) {
                    it.remove();
                    result = true;
                }
            }
        } else {
            Iterator<?> it = collection.iterator();
            while (it.hasNext()) {
                result = remove(it.next()) || result;
            }
        }
        return result;