Top Description Constructors Methods
com.google.common.collect

public abstract Class ForwardingSet<E extends @Nullable Object>

extends ForwardingCollection<E extends @Nullable Object>
implements Set<E extends @Nullable Object>
Class Inheritance
All Implemented Interfaces
java.util.Set, java.util.Collection, java.lang.Iterable
Known Direct Subclasses
com.google.common.collect.ForwardingSortedSet, com.google.common.collect.Maps.FilteredEntryMap.EntrySet, com.google.common.reflect.TypeToken.TypeSet, com.google.common.collect.AbstractBiMap.KeySet, com.google.common.collect.AbstractBiMap.ValueSet, com.google.common.collect.AbstractBiMap.EntrySet, com.google.common.collect.FilteredKeyMultimap.AddRejectingSet
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkNotNull

A set which forwards all its method calls to another set. Subclasses should override one or more methods to modify the behavior of the backing set as desired per the decorator pattern.

Warning

The methods of ForwardingSet forward indiscriminately to the methods of the delegate. For example, overriding add alone will not change the behavior of addAll, which can lead to unexpected behavior. In this case, you should override addAll as well, either providing your own implementation, or delegating to the provided standardAddAll method.

default method warning: This class does not forward calls to default methods. Instead, it inherits their default implementations. When those implementations invoke methods, they invoke methods on the ForwardingSet.

The standard methods are not guaranteed to be thread-safe, even when all of the methods that they depend on are thread-safe.

Authors
Kevin Bourrillion, Louis Wasserman
Since
2.0

Constructor Summary

AccessConstructor and Description
protected
ForwardingSet()

Constructor for use by subclasses.

Method Summary

Modifier and TypeMethod and Description
protected abstract Set<E>
delegate()

Implements abstract com.google.common.collect.ForwardingCollection.delegate.

Returns the backing delegate instance that methods are forwarded to.
public boolean
equals(Object
object to be compared for equality with this set
object
)

Overrides java.lang.Object.equals.

Implements java.util.Set.equals, java.util.Collection.equals.

Compares the specified object with this set for equality.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Set.hashCode, java.util.Collection.hashCode.

Returns the hash code value for this set.
protected boolean
standardEquals(Object object)

A sensible definition of equals in terms of size and containsAll.

protected int
standardHashCode()

A sensible definition of hashCode in terms of iterator.

protected boolean
Inherited from com.google.common.collect.ForwardingCollection:
addaddAllclearcontainscontainsAllisEmptyiteratorremoveremoveAllretainAllsizestandardAddAllstandardClearstandardContainsstandardContainsAllstandardIsEmptystandardRemovestandardRetainAllstandardToArraystandardToArraystandardToStringtoArraytoArray

Constructor Detail

ForwardingSetback to summary
protected ForwardingSet()

Constructor for use by subclasses.

Method Detail

delegateback to summary
protected abstract Set<E> delegate()

Implements abstract com.google.common.collect.ForwardingCollection.delegate.

Doc from com.google.common.collect.ForwardingObject.delegate.

Returns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such as ForwardingSet#delegate. Concrete subclasses override this method to supply the instance being decorated.

Annotations
@Override
equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Implements java.util.Set.equals, java.util.Collection.equals.

Doc from java.util.Set.equals.

Compares the specified object with this set for equality. Returns true if the specified object is also a set, the two sets have the same size, and every member of the specified set is contained in this set (or equivalently, every member of this set is contained in the specified set). This definition ensures that the equals method works properly across different implementations of the set interface.

Parameters
object:Object

object to be compared for equality with this set

Returns:boolean

true if the specified object is equal to this set

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Set.hashCode, java.util.Collection.hashCode.

Doc from java.util.Set.hashCode.

Returns the hash code value for this set. The hash code of a set is defined to be the sum of the hash codes of the elements in the set, where the hash code of a null element is defined to be zero. 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.

Returns:int

the hash code value for this set

Annotations
@Override
standardEqualsback to summary
protected boolean standardEquals(Object object)

A sensible definition of equals in terms of size and containsAll. If you override either of those methods, you may wish to override equals to forward to this implementation.

Since
7.0
standardHashCodeback to summary
protected int standardHashCode()

A sensible definition of hashCode in terms of iterator. If you override iterator, you may wish to override equals to forward to this implementation.

Since
7.0
standardRemoveAllback to summary
protected boolean standardRemoveAll(Collection<?> collection)

Overrides com.google.common.collect.ForwardingCollection.standardRemoveAll.

A sensible definition of removeAll in terms of iterator and remove. If you override iterator or remove, you may wish to override removeAll to forward to this implementation.

Annotations
@Override
Since
7.0 (this version overrides the ForwardingCollection version as of 12.0)