Package com.google.common.collect
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
public abstract static class Sets.SetView<E extends @Nullable Object> extends AbstractSet<E>
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 typeSetView
; typically, you either use it as a plainSet
, or immediately invokeimmutableCopy()
orcopyInto(S)
and forget theSetView
itself.- Since:
- 2.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
add(E e)
Deprecated.Unsupported operation.boolean
addAll(Collection<? extends E> newElements)
Deprecated.Unsupported operation.void
clear()
Deprecated.Unsupported operation.<S extends Set<E>>
ScopyInto(S set)
Copies the current contents of this set view into an existing set.ImmutableSet<@NonNull E>
immutableCopy()
Returns an immutable copy of the current contents of this set view.abstract UnmodifiableIterator<E>
iterator()
Scope the return type toUnmodifiableIterator
to ensure this is an unmodifiable view.boolean
remove(@Nullable Object object)
Deprecated.Unsupported operation.boolean
removeAll(Collection<?> oldElements)
Deprecated.Unsupported operation.boolean
removeIf(Predicate<? super E> filter)
Deprecated.Unsupported operation.boolean
retainAll(Collection<?> elementsToKeep)
Deprecated.Unsupported operation.-
Methods inherited from class java.util.AbstractSet
equals, hashCode
-
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, size, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
-
Methods inherited from interface java.util.Set
contains, containsAll, isEmpty, size, spliterator, toArray, toArray
-
-
-
-
Method Detail
-
immutableCopy
public ImmutableSet<@NonNull E> 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
TreeSet
using a comparator that is inconsistent withObject.equals(Object)
.
-
copyInto
@CanIgnoreReturnValue public <S extends Set<E>> S copyInto(S set)
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
@CanIgnoreReturnValue @Deprecated public final boolean add(E e)
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
add
in interfaceCollection<E extends @Nullable Object>
- Specified by:
add
in interfaceSet<E extends @Nullable Object>
- Overrides:
add
in classAbstractCollection<E extends @Nullable Object>
- Throws:
UnsupportedOperationException
- always
-
remove
@CanIgnoreReturnValue @Deprecated public final boolean remove(@Nullable Object object)
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
remove
in interfaceCollection<E extends @Nullable Object>
- Specified by:
remove
in interfaceSet<E extends @Nullable Object>
- Overrides:
remove
in classAbstractCollection<E extends @Nullable Object>
- Throws:
UnsupportedOperationException
- always
-
addAll
@CanIgnoreReturnValue @Deprecated public final boolean addAll(Collection<? extends E> newElements)
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
addAll
in interfaceCollection<E extends @Nullable Object>
- Specified by:
addAll
in interfaceSet<E extends @Nullable Object>
- Overrides:
addAll
in classAbstractCollection<E extends @Nullable Object>
- Throws:
UnsupportedOperationException
- always
-
removeAll
@CanIgnoreReturnValue @Deprecated public final boolean removeAll(Collection<?> oldElements)
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
removeAll
in interfaceCollection<E extends @Nullable Object>
- Specified by:
removeAll
in interfaceSet<E extends @Nullable Object>
- Overrides:
removeAll
in classAbstractSet<E extends @Nullable Object>
- Throws:
UnsupportedOperationException
- always
-
removeIf
@CanIgnoreReturnValue @Deprecated public final boolean removeIf(Predicate<? super E> filter)
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Throws:
UnsupportedOperationException
- always
-
retainAll
@CanIgnoreReturnValue @Deprecated public final boolean retainAll(Collection<?> elementsToKeep)
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
retainAll
in interfaceCollection<E extends @Nullable Object>
- Specified by:
retainAll
in interfaceSet<E extends @Nullable Object>
- Overrides:
retainAll
in classAbstractCollection<E extends @Nullable Object>
- Throws:
UnsupportedOperationException
- always
-
clear
@Deprecated public final void clear()
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
clear
in interfaceCollection<E extends @Nullable Object>
- Specified by:
clear
in interfaceSet<E extends @Nullable Object>
- Overrides:
clear
in classAbstractCollection<E extends @Nullable Object>
- Throws:
UnsupportedOperationException
- always
-
iterator
public abstract UnmodifiableIterator<E> iterator()
Scope the return type toUnmodifiableIterator
to ensure this is an unmodifiable view.- Specified by:
iterator
in interfaceCollection<E extends @Nullable Object>
- Specified by:
iterator
in interfaceIterable<E extends @Nullable Object>
- Specified by:
iterator
in interfaceSet<E extends @Nullable Object>
- Specified by:
iterator
in classAbstractCollection<E extends @Nullable Object>
- Since:
- 20.0 (present with return type
Iterator
since 2.0)
-
-