Class ForwardingMap.StandardKeySet
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- com.google.common.collect.ForwardingMap.StandardKeySet
-
- All Implemented Interfaces:
Iterable<K>
,Collection<K>
,Set<K>
@Beta protected class ForwardingMap.StandardKeySet extends AbstractSet<E>
A sensible implementation ofMap.keySet()
in terms of the following methods:ForwardingMap.clear()
,ForwardingMap.containsKey(java.lang.Object)
,ForwardingMap.isEmpty()
,ForwardingMap.remove(java.lang.Object)
,ForwardingMap.size()
, and theSet.iterator()
method ofForwardingMap.entrySet()
. In many cases, you may wish to overrideForwardingMap.keySet()
to forward to this implementation or a subclass thereof.- Since:
- 10.0
-
-
Constructor Summary
Constructors Constructor Description StandardKeySet()
Constructor for use by subclasses.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes all of the elements from this collection (optional operation).boolean
contains(Object o)
Returnstrue
if this collection contains the specified element.boolean
isEmpty()
Returnstrue
if this collection contains no elements.Iterator<K>
iterator()
Returns an iterator over the elements contained in this collection.boolean
remove(Object o)
Removes a single instance of the specified element from this collection, if it is present (optional operation).boolean
removeAll(Collection<?> c)
Removes from this set all of its elements that are contained in the specified collection (optional operation).boolean
retainAll(Collection<?> c)
Retains only the elements in this collection that are contained in the specified collection (optional operation).int
size()
Returns the number of elements in this collection.-
Methods inherited from class java.util.AbstractSet
equals, hashCode
-
Methods inherited from class java.util.AbstractCollection
add, addAll, containsAll, 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
add, addAll, containsAll, spliterator, toArray, toArray
-
-
-
-
Constructor Detail
-
StandardKeySet
public StandardKeySet()
Constructor for use by subclasses.
-
-
Method Detail
-
iterator
public Iterator<K> iterator()
Description copied from class:java.util.AbstractCollection
Returns an iterator over the elements contained in this collection.- Specified by:
iterator
in interfaceCollection<K extends @Nullable Object>
- Specified by:
iterator
in interfaceIterable<K extends @Nullable Object>
- Specified by:
iterator
in interfaceSet<K extends @Nullable Object>
- Specified by:
iterator
in classAbstractCollection<K extends @Nullable Object>
- Returns:
- an iterator over the elements contained in this collection
-
size
public int size()
Description copied from interface:java.util.Collection
Returns the number of elements in this collection. If this collection contains more thanInteger.MAX_VALUE
elements, returnsInteger.MAX_VALUE
.
-
isEmpty
public boolean isEmpty()
Description copied from class:java.util.AbstractCollection
Returnstrue
if this collection contains no elements.
-
contains
public boolean contains(@CheckForNull Object o)
Description copied from class:java.util.AbstractCollection
Returnstrue
if this collection contains the specified element. More formally, returnstrue
if and only if this collection contains at least one elemente
such thatObjects.equals(o, e)
.- Specified by:
contains
in interfaceCollection<K extends @Nullable Object>
- Specified by:
contains
in interfaceSet<K extends @Nullable Object>
- Overrides:
contains
in classAbstractCollection<K extends @Nullable Object>
- Parameters:
o
- element whose presence in this collection is to be tested- Returns:
true
if this collection contains the specified element
-
remove
public boolean remove(@CheckForNull Object o)
Description copied from class:java.util.AbstractCollection
Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an elemente
such thatObjects.equals(o, e)
, if this collection contains one or more such elements. Returnstrue
if this collection contained the specified element (or equivalently, if this collection changed as a result of the call).- Specified by:
remove
in interfaceCollection<K extends @Nullable Object>
- Specified by:
remove
in interfaceSet<K extends @Nullable Object>
- Overrides:
remove
in classAbstractCollection<K extends @Nullable Object>
- Parameters:
o
- element to be removed from this collection, if present- Returns:
true
if an element was removed as a result of this call
-
clear
public void clear()
Description copied from class:java.util.AbstractCollection
Removes all of the elements from this collection (optional operation). The collection will be empty after this method returns.
-
removeAll
public boolean removeAll(Collection<?> c)
Description copied from class:java.util.AbstractSet
Removes from this set all of its elements that are contained in the specified collection (optional operation). If the specified collection is also a set, this operation effectively modifies this set so that its value is the asymmetric set difference of the two sets.This implementation determines which is the smaller of this set and the specified collection, by invoking the
size
method on each. If this set has fewer elements, then the implementation iterates over this set, checking each element returned by the iterator in turn to see if it is contained in the specified collection. If it is so contained, it is removed from this set with the iterator'sremove
method. If the specified collection has fewer elements, then the implementation iterates over the specified collection, removing from this set each element returned by the iterator, using this set'sremove
method.Note that this implementation will throw an
UnsupportedOperationException
if the iterator returned by theiterator
method does not implement theremove
method.- 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>
- Parameters:
c
- collection containing elements to be removed from this set- Returns:
true
if this set changed as a result of the call- See Also:
AbstractCollection.remove(Object)
,AbstractCollection.contains(Object)
-
retainAll
public boolean retainAll(Collection<?> c)
Description copied from class:java.util.AbstractCollection
Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.- 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>
- Parameters:
c
- collection containing elements to be retained in this collection- Returns:
true
if this collection changed as a result of the call- See Also:
AbstractCollection.remove(Object)
,AbstractCollection.contains(Object)
-
-