Class Sets.SetView<E>
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
-
Method Summary
Modifier and TypeMethodDescriptioncopyInto(S set) Copies the current contents of this set view into an existing set.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.Methods inherited from class AbstractSet
equals, hashCode, removeAllMethods inherited from class AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, remove, retainAll, size, toArray, toArray, toStringMethods inherited from interface Collection
parallelStream, removeIf, stream, 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
-
iterator
Scope the return type toUnmodifiableIteratorto ensure this is an unmodifiable view.
-