Package com.google.common.collect
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
public abstract static class Sets.SetView<E> 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 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(Collection<? extends E> newElements)Deprecated.Unsupported operation.voidclear()Deprecated.Unsupported operation.<S extends Set<E>>
ScopyInto(S set)Copies the current contents of this set view into an existing set.ImmutableSet<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(Object object)Deprecated.Unsupported operation.booleanremoveAll(Collection<?> oldElements)Deprecated.Unsupported operation.booleanretainAll(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, removeIf, stream, toArray
-
Methods inherited from interface java.util.Set
contains, containsAll, isEmpty, size, spliterator, toArray, toArray
-
-
-
-
Method Detail
-
immutableCopy
public ImmutableSet<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 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 interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classAbstractCollection<E>- Parameters:
e- element whose presence in this collection is to be ensured- Returns:
trueif this collection changed as a result of the call- Throws:
UnsupportedOperationException- always
-
remove
@CanIgnoreReturnValue @Deprecated public final boolean remove(Object object)
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>- Parameters:
object- element to be removed from this collection, if present- Returns:
trueif an element was removed as a result of this call- 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:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceSet<E>- Overrides:
addAllin classAbstractCollection<E>- Parameters:
newElements- collection containing elements to be added to this collection- Returns:
trueif this collection changed as a result of the call- Throws:
UnsupportedOperationException- always- See Also:
AbstractCollection.add(Object)
-
removeAll
@CanIgnoreReturnValue @Deprecated public final boolean removeAll(Collection<?> oldElements)
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceSet<E>- Overrides:
removeAllin classAbstractSet<E>- Parameters:
oldElements- collection containing elements to be removed from this set- Returns:
trueif this set changed as a result of the call- Throws:
UnsupportedOperationException- always- See Also:
AbstractCollection.remove(Object),AbstractCollection.contains(Object)
-
retainAll
@CanIgnoreReturnValue @Deprecated public final boolean retainAll(Collection<?> elementsToKeep)
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceSet<E>- Overrides:
retainAllin classAbstractCollection<E>- Parameters:
elementsToKeep- collection containing elements to be retained in this collection- Returns:
trueif this collection changed as a result of the call- Throws:
UnsupportedOperationException- always- See Also:
AbstractCollection.remove(Object),AbstractCollection.contains(Object)
-
clear
@Deprecated public final void clear()
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Overrides:
clearin classAbstractCollection<E>- Throws:
UnsupportedOperationException- always
-
iterator
public abstract UnmodifiableIterator<E> iterator()
Scope the return type toUnmodifiableIteratorto ensure this is an unmodifiable view.- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin interfaceSet<E>- Specified by:
iteratorin classAbstractCollection<E>- Returns:
- an iterator over the elements contained in this collection
- Since:
- 20.0 (present with return type
Iteratorsince 2.0)
-
-