Class Sets.SetView<E extends @Nullable Object>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
com.google.common.collect.Sets.SetView<E>
- All Implemented Interfaces:
Iterable<E>, Collection<E>, Set<E>
- Enclosing class:
Sets
An unmodifiable view of a set which may be backed by other sets; this view will change as the
backing sets do. Contains methods to copy the data into a new set which will then remain
stable. There is usually no reason to retain a reference of type
SetView; typically,
you either use it as a plain Set, or immediately invoke immutableCopy() or
copyInto(S) and forget the SetView itself.- Since:
- 2.0
- Author:
- Kevin Bourrillion, Jared Levy, Chris Povirk
-
Method Summary
Modifier and TypeMethodDescriptionfinal booleanDeprecated.Unsupported operation.final booleanaddAll(Collection<? extends E> newElements) Deprecated.Unsupported operation.final voidclear()Deprecated.Unsupported operation.copyInto(S set) Copies the current contents of this set view into an existing set.ImmutableSet<@NonNull E> Returns an immutable copy of the current contents of this set view.abstract UnmodifiableIterator<E> iterator()Scope the return type toUnmodifiableIteratorto ensure this is an unmodifiable view.final booleanDeprecated.Unsupported operation.final booleanremoveAll(Collection<?> oldElements) Deprecated.Unsupported operation.final booleanDeprecated.Unsupported operation.final booleanretainAll(Collection<?> elementsToKeep) Deprecated.Unsupported operation.Methods inherited from class AbstractSet
equals, hashCodeMethods inherited from class AbstractCollection
contains, containsAll, isEmpty, size, toArray, toArray, toStringMethods inherited from interface Collection
parallelStream, stream, toArrayMethods inherited from interface Set
contains, containsAll, isEmpty, size, spliterator, toArray, toArray
-
Method Details
-
immutableCopy
Returns an immutable copy of the current contents of this set view. Does not support null elements.Warning: this may have unexpected results if a backing set of this view uses a nonstandard notion of equivalence, for example if it is a
TreeSetusing a comparator that is inconsistent withObject.equals(Object). -
copyInto
Copies the current contents of this set view into an existing set. This method has equivalent behavior toset.addAll(this), assuming that all the sets involved are based on the same notion of equivalence.- Returns:
- a reference to
set, for convenience
-
add
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
addin interfaceCollection<E extends @Nullable Object>- Specified by:
addin interfaceSet<E extends @Nullable Object>- Overrides:
addin classAbstractCollection<E extends @Nullable Object>- Throws:
UnsupportedOperationException- always
-
remove
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
removein interfaceCollection<E extends @Nullable Object>- Specified by:
removein interfaceSet<E extends @Nullable Object>- Overrides:
removein classAbstractCollection<E extends @Nullable Object>- Throws:
UnsupportedOperationException- always
-
addAll
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
addAllin interfaceCollection<E extends @Nullable Object>- Specified by:
addAllin interfaceSet<E extends @Nullable Object>- Overrides:
addAllin classAbstractCollection<E extends @Nullable Object>- Throws:
UnsupportedOperationException- always
-
removeAll
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
removeAllin interfaceCollection<E extends @Nullable Object>- Specified by:
removeAllin interfaceSet<E extends @Nullable Object>- Overrides:
removeAllin classAbstractSet<E extends @Nullable Object>- Throws:
UnsupportedOperationException- always
-
removeIf
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Throws:
UnsupportedOperationException- always
-
retainAll
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
retainAllin interfaceCollection<E extends @Nullable Object>- Specified by:
retainAllin interfaceSet<E extends @Nullable Object>- Overrides:
retainAllin classAbstractCollection<E extends @Nullable Object>- Throws:
UnsupportedOperationException- always
-
clear
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
clearin interfaceCollection<E extends @Nullable Object>- Specified by:
clearin interfaceSet<E extends @Nullable Object>- Overrides:
clearin classAbstractCollection<E extends @Nullable Object>- Throws:
UnsupportedOperationException- always
-
iterator
Scope the return type toUnmodifiableIteratorto ensure this is an unmodifiable view.- Specified by:
iteratorin interfaceCollection<E extends @Nullable Object>- Specified by:
iteratorin interfaceIterable<E extends @Nullable Object>- Specified by:
iteratorin interfaceSet<E extends @Nullable Object>- Specified by:
iteratorin classAbstractCollection<E extends @Nullable Object>- Since:
- 20.0 (present with return type
Iteratorsince 2.0)
-