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.EntrySetNested classes/interfaces inherited from interface com.google.common.collect.Multiset
Multiset.Entry<E> -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleanDetermines whether this multiset contains the specified element.intReturns the number of occurrences of an element in this multiset (the count of the element).(package private) intReturns the set of distinct elements contained in this multiset.(package private) Iterator<Multiset.Entry<K>>voiditerator()intRemoves a number of occurrences of the specified element from this multiset.intsize()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, toStringMethods inherited from class java.util.AbstractCollection
containsAll, toArray, toArrayMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray, toArray, toArrayMethods 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:
entryIteratorin classAbstractMultiset<K>
-
spliterator
-
forEach
Description copied from interface:MultisetElements that occur multiple times in the multiset will be passed to the
Consumercorrespondingly many times, though not necessarily sequentially. -
distinctElements
int distinctElements()- Specified by:
distinctElementsin classAbstractMultiset<K>
-
size
public int size()Description copied from interface:MultisetReturns 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:
sizein interfaceCollection<K>- Specified by:
sizein interfaceMultiset<K>- Specified by:
sizein classAbstractCollection<K>
-
contains
Description copied from interface:MultisetDetermines 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 toelementbeing null or of the wrong type.- Specified by:
containsin interfaceCollection<K>- Specified by:
containsin interfaceMultiset<K>- Overrides:
containsin classAbstractMultiset<K>- Parameters:
element- the element to check for- Returns:
trueif this multiset contains at least one occurrence of the element
-
iterator
Description copied from interface:MultisetElements that occur multiple times in the multiset will appear multiple times in this iterator, though not necessarily sequentially.
-
count
Description copied from interface:MultisetReturns 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:MultisetRemoves 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:
removein interfaceMultiset<K>- Overrides:
removein 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:
clearin interfaceCollection<K>- Specified by:
clearin classAbstractMultiset<K>
-
elementSet
Description copied from interface:MultisetReturns 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:
elementSetin interfaceMultiset<K>- Overrides:
elementSetin classAbstractMultiset<K>- Returns:
- a view of the set of distinct elements in this multiset
-
elementIterator
- Specified by:
elementIteratorin classAbstractMultiset<K>
-