Package com.google.common.collect
Class Sets.SetView<E extends @Nullable java.lang.Object>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- com.google.common.collect.Sets.SetView<E>
-
- All Implemented Interfaces:
java.lang.Iterable<E>,java.util.Collection<E>,java.util.Set<E>
- Enclosing class:
- Sets
public abstract static class Sets.SetView<E extends @Nullable java.lang.Object> extends java.util.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 theSetViewitself.- Since:
- 2.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanadd(E e)Deprecated.Unsupported operation.booleanaddAll(java.util.Collection<? extends E> newElements)Deprecated.Unsupported operation.voidclear()Deprecated.Unsupported operation.<S extends java.util.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 toUnmodifiableIteratorto ensure this is an unmodifiable view.booleanremove(java.lang.Object object)Deprecated.Unsupported operation.booleanremoveAll(java.util.Collection<?> oldElements)Deprecated.Unsupported operation.booleanremoveIf(java.util.function.Predicate<? super E> filter)Deprecated.Unsupported operation.booleanretainAll(java.util.Collection<?> elementsToKeep)Deprecated.Unsupported operation.-
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, size, toArray, toArray, toString
-
-
-
-
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
TreeSetusing a comparator that is inconsistent withObject.equals(Object).
-
copyInto
@CanIgnoreReturnValue public <S extends java.util.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:
addin interfacejava.util.Collection<E extends @Nullable java.lang.Object>- Specified by:
addin interfacejava.util.Set<E extends @Nullable java.lang.Object>- Overrides:
addin classjava.util.AbstractCollection<E extends @Nullable java.lang.Object>- Throws:
java.lang.UnsupportedOperationException- always
-
remove
@CanIgnoreReturnValue @Deprecated public final boolean remove(@CheckForNull java.lang.Object object)
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
removein interfacejava.util.Collection<E extends @Nullable java.lang.Object>- Specified by:
removein interfacejava.util.Set<E extends @Nullable java.lang.Object>- Overrides:
removein classjava.util.AbstractCollection<E extends @Nullable java.lang.Object>- Throws:
java.lang.UnsupportedOperationException- always
-
addAll
@CanIgnoreReturnValue @Deprecated public final boolean addAll(java.util.Collection<? extends E> newElements)
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
addAllin interfacejava.util.Collection<E extends @Nullable java.lang.Object>- Specified by:
addAllin interfacejava.util.Set<E extends @Nullable java.lang.Object>- Overrides:
addAllin classjava.util.AbstractCollection<E extends @Nullable java.lang.Object>- Throws:
java.lang.UnsupportedOperationException- always
-
removeAll
@CanIgnoreReturnValue @Deprecated public final boolean removeAll(java.util.Collection<?> oldElements)
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
removeAllin interfacejava.util.Collection<E extends @Nullable java.lang.Object>- Specified by:
removeAllin interfacejava.util.Set<E extends @Nullable java.lang.Object>- Overrides:
removeAllin classjava.util.AbstractSet<E extends @Nullable java.lang.Object>- Throws:
java.lang.UnsupportedOperationException- always
-
removeIf
@CanIgnoreReturnValue @Deprecated public final boolean removeIf(java.util.function.Predicate<? super E> filter)
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Throws:
java.lang.UnsupportedOperationException- always
-
retainAll
@CanIgnoreReturnValue @Deprecated public final boolean retainAll(java.util.Collection<?> elementsToKeep)
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
retainAllin interfacejava.util.Collection<E extends @Nullable java.lang.Object>- Specified by:
retainAllin interfacejava.util.Set<E extends @Nullable java.lang.Object>- Overrides:
retainAllin classjava.util.AbstractCollection<E extends @Nullable java.lang.Object>- Throws:
java.lang.UnsupportedOperationException- always
-
clear
@Deprecated public final void clear()
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
clearin interfacejava.util.Collection<E extends @Nullable java.lang.Object>- Specified by:
clearin interfacejava.util.Set<E extends @Nullable java.lang.Object>- Overrides:
clearin classjava.util.AbstractCollection<E extends @Nullable java.lang.Object>- Throws:
java.lang.UnsupportedOperationException- always
-
iterator
public abstract UnmodifiableIterator<E> iterator()
Scope the return type toUnmodifiableIteratorto ensure this is an unmodifiable view.- Specified by:
iteratorin interfacejava.util.Collection<E extends @Nullable java.lang.Object>- Specified by:
iteratorin interfacejava.lang.Iterable<E extends @Nullable java.lang.Object>- Specified by:
iteratorin interfacejava.util.Set<E extends @Nullable java.lang.Object>- Specified by:
iteratorin classjava.util.AbstractCollection<E extends @Nullable java.lang.Object>- Since:
- 20.0 (present with return type
Iteratorsince 2.0)
-
-