Class Multimaps.Keys<K,V>
- All Implemented Interfaces:
Multiset<K>
,Iterable<K>
,Collection<K>
- Direct Known Subclasses:
FilteredEntryMultimap.Keys
- Enclosing class:
Multimaps
-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.common.collect.AbstractMultiset
AbstractMultiset.ElementSet, AbstractMultiset.EntrySet
Nested classes/interfaces inherited from interface com.google.common.collect.Multiset
Multiset.Entry<E>
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
boolean
Determines whether this multiset contains the specified element.int
Returns the number of occurrences of an element in this multiset (the count of the element).(package private) int
Returns the set of distinct elements contained in this multiset.(package private) Iterator
<Multiset.Entry<K>> void
iterator()
int
Removes a number of occurrences of the specified element from this multiset.int
size()
Returns the total number of all occurrences of all elements in this multiset.Methods inherited from class com.google.common.collect.AbstractMultiset
add, add, addAll, createElementSet, createEntrySet, entrySet, equals, hashCode, isEmpty, remove, removeAll, retainAll, setCount, setCount, toString
Methods inherited from class java.util.AbstractCollection
containsAll, toArray, toArray
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, toArray, toArray
Methods inherited from interface com.google.common.collect.Multiset
containsAll, forEachEntry
-
Field Details
-
multimap
-
-
Constructor Details
-
Keys
-
-
Method Details
-
entryIterator
Iterator<Multiset.Entry<K>> entryIterator()- Specified by:
entryIterator
in classAbstractMultiset<K>
-
spliterator
-
forEach
Description copied from interface:Multiset
Elements that occur multiple times in the multiset will be passed to the
Consumer
correspondingly many times, though not necessarily sequentially. -
distinctElements
int distinctElements()- Specified by:
distinctElements
in classAbstractMultiset<K>
-
size
public int size()Description copied from interface:Multiset
Returns the total number of all occurrences of all elements in this multiset.Note: this method does not return the number of distinct elements in the multiset, which is given by
entrySet().size()
.- Specified by:
size
in interfaceCollection<K>
- Specified by:
size
in interfaceMultiset<K>
- Specified by:
size
in classAbstractCollection<K>
-
contains
Description copied from interface:Multiset
Determines whether this multiset contains the specified element.This method refines
Collection.contains(java.lang.Object)
to further specify that it may not throw an exception in response toelement
being null or of the wrong type.- Specified by:
contains
in interfaceCollection<K>
- Specified by:
contains
in interfaceMultiset<K>
- Overrides:
contains
in classAbstractMultiset<K>
- Parameters:
element
- the element to check for- Returns:
true
if this multiset contains at least one occurrence of the element
-
iterator
Description copied from interface:Multiset
Elements that occur multiple times in the multiset will appear multiple times in this iterator, though not necessarily sequentially.
-
count
Description copied from interface:Multiset
Returns the number of occurrences of an element in this multiset (the count of the element). Note that for anObject.equals(java.lang.Object)
-based multiset, this gives the same result asCollections.frequency(java.util.Collection<?>, java.lang.Object)
(which would presumably perform more poorly).Note: the utility method
Iterables.frequency(java.lang.Iterable<?>, java.lang.Object)
generalizes this operation; it correctly delegates to this method when dealing with a multiset, but it can also accept any other iterable type.- Parameters:
element
- the element to count occurrences of- Returns:
- the number of occurrences of the element in this multiset; possibly zero but never negative
-
remove
Description copied from interface:Multiset
Removes a number of occurrences of the specified element from this multiset. If the multiset contains fewer than this number of occurrences to begin with, all occurrences will be removed. Note that ifoccurrences == 1
, this is functionally equivalent to the callremove(element)
.- Specified by:
remove
in interfaceMultiset<K>
- Overrides:
remove
in classAbstractMultiset<K>
- Parameters:
element
- the element to conditionally remove occurrences ofoccurrences
- the number of occurrences of the element to remove. May be zero, in which case no change will be made.- Returns:
- the count of the element before the operation; possibly zero
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<K>
- Specified by:
clear
in classAbstractMultiset<K>
-
elementSet
Description copied from interface:Multiset
Returns the set of distinct elements contained in this multiset. The element set is backed by the same data as the multiset, so any change to either is immediately reflected in the other. The order of the elements in the element set is unspecified.If the element set supports any removal operations, these necessarily cause all occurrences of the removed element(s) to be removed from the multiset. Implementations are not expected to support the add operations, although this is possible.
A common use for the element set is to find the number of distinct elements in the multiset:
elementSet().size()
.- Specified by:
elementSet
in interfaceMultiset<K>
- Overrides:
elementSet
in classAbstractMultiset<K>
- Returns:
- a view of the set of distinct elements in this multiset
-
elementIterator
- Specified by:
elementIterator
in classAbstractMultiset<K>
-