Package com.google.common.collect
Class ForwardingMap.StandardValues
- java.lang.Object
-
- java.util.AbstractCollection<V>
-
- com.google.common.collect.ForwardingMap.StandardValues
-
- All Implemented Interfaces:
Iterable<V>,Collection<V>
- Enclosing class:
- ForwardingMap<K,V>
@Beta protected class ForwardingMap.StandardValues extends AbstractCollection<V>
A sensible implementation ofMap.values()in terms of the following methods:ForwardingMap.clear(),ForwardingMap.containsValue(java.lang.Object),ForwardingMap.isEmpty(),ForwardingMap.size(), and theSet.iterator()method ofForwardingMap.entrySet(). In many cases, you may wish to overrideForwardingMap.values()to forward to this implementation or a subclass thereof.- Since:
- 10.0
-
-
Constructor Summary
Constructors Constructor Description StandardValues()Constructor for use by subclasses.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Removes all of the elements from this collection (optional operation).booleancontains(@Nullable Object o)Returnstrueif this collection contains the specified element.voidforEach(Consumer<? super V> action)Performs the given action for each element of theIterableuntil all elements have been processed or the action throws an exception.booleanisEmpty()Returnstrueif this collection contains no elements.Iterator<V>iterator()Returns an iterator over the elements contained in this collection.booleanremove(Object o)Removes a single instance of the specified element from this collection, if it is present (optional operation).booleanremoveAll(Collection<?> c)Removes all of this collection's elements that are also contained in the specified collection (optional operation).booleanretainAll(Collection<?> c)Retains only the elements in this collection that are contained in the specified collection (optional operation).intsize()Returns the number of elements in this collection.-
Methods inherited from class java.util.AbstractCollection
add, addAll, containsAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
-
-
-
Constructor Detail
-
StandardValues
public StandardValues()
Constructor for use by subclasses.
-
-
Method Detail
-
iterator
public Iterator<V> iterator()
Description copied from class:java.util.AbstractCollectionReturns an iterator over the elements contained in this collection.- Specified by:
iteratorin interfaceCollection<K>- Specified by:
iteratorin interfaceIterable<K>- Specified by:
iteratorin classAbstractCollection<V>- Returns:
- an iterator over the elements contained in this collection
-
forEach
public void forEach(Consumer<? super V> action)
Description copied from interface:java.lang.IterablePerforms the given action for each element of theIterableuntil all elements have been processed or the action throws an exception. Actions are performed in the order of iteration, if that order is specified. Exceptions thrown by the action are relayed to the caller.The behavior of this method is unspecified if the action performs side-effects that modify the underlying source of elements, unless an overriding class has specified a concurrent modification policy.
- Parameters:
action- The action to be performed for each element
-
remove
public boolean remove(Object o)
Description copied from class:java.util.AbstractCollectionRemoves a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an elementesuch thatObjects.equals(o, e), if this collection contains one or more such elements. Returnstrueif this collection contained the specified element (or equivalently, if this collection changed as a result of the call).- Specified by:
removein interfaceCollection<K>- Overrides:
removein classAbstractCollection<V>- Parameters:
o- element to be removed from this collection, if present- Returns:
trueif an element was removed as a result of this call
-
removeAll
public boolean removeAll(Collection<?> c)
Description copied from class:java.util.AbstractCollectionRemoves all of this collection's elements that are also contained in the specified collection (optional operation). After this call returns, this collection will contain no elements in common with the specified collection.- Specified by:
removeAllin interfaceCollection<K>- Overrides:
removeAllin classAbstractCollection<V>- Parameters:
c- collection containing elements to be removed from this collection- Returns:
trueif this collection 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.AbstractCollectionRetains 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:
retainAllin interfaceCollection<K>- Overrides:
retainAllin classAbstractCollection<V>- Parameters:
c- collection containing elements to be retained in this collection- Returns:
trueif this collection changed as a result of the call- See Also:
AbstractCollection.remove(Object),AbstractCollection.contains(Object)
-
size
public int size()
Description copied from interface:java.util.CollectionReturns the number of elements in this collection. If this collection contains more thanInteger.MAX_VALUEelements, returnsInteger.MAX_VALUE.- Specified by:
sizein interfaceCollection<K>- Specified by:
sizein classAbstractCollection<V>- Returns:
- the number of elements in this collection
-
isEmpty
public boolean isEmpty()
Description copied from class:java.util.AbstractCollectionReturnstrueif this collection contains no elements.- Specified by:
isEmptyin interfaceCollection<K>- Overrides:
isEmptyin classAbstractCollection<V>- Returns:
trueif this collection contains no elements
-
contains
public boolean contains(@Nullable Object o)
Description copied from class:java.util.AbstractCollectionReturnstrueif this collection contains the specified element. More formally, returnstrueif and only if this collection contains at least one elementesuch thatObjects.equals(o, e).- Specified by:
containsin interfaceCollection<K>- Overrides:
containsin classAbstractCollection<V>- Parameters:
o- element whose presence in this collection is to be tested- Returns:
trueif this collection contains the specified element
-
clear
public void clear()
Description copied from class:java.util.AbstractCollectionRemoves all of the elements from this collection (optional operation). The collection will be empty after this method returns.- Specified by:
clearin interfaceCollection<K>- Overrides:
clearin classAbstractCollection<V>
-
-