Class Multimaps.Keys<K,V>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- com.google.common.collect.AbstractMultiset<K>
-
- com.google.common.collect.Multimaps.Keys<K,V>
-
- All Implemented Interfaces:
Multiset<K>
,java.lang.Iterable<K>
,java.util.Collection<K>
- Direct Known Subclasses:
FilteredEntryMultimap.Keys
- Enclosing class:
- Multimaps
static class Multimaps.Keys<K,V> extends AbstractMultiset<K>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
Multimaps.Keys.KeysEntrySet
-
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>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
contains(java.lang.Object element)
Determines whether this multiset contains the specified element.int
count(java.lang.Object element)
Returns the number of occurrences of an element in this multiset (the count of the element).(package private) java.util.Set<Multiset.Entry<K>>
createEntrySet()
(package private) int
distinctElements()
java.util.Set<K>
elementSet()
Returns the set of distinct elements contained in this multiset.(package private) java.util.Iterator<Multiset.Entry<K>>
entryIterator()
java.util.Iterator<K>
iterator()
int
remove(java.lang.Object element, int occurrences)
Removes a number of occurrences of the specified element from this multiset.-
Methods inherited from class com.google.common.collect.AbstractMultiset
add, add, addAll, createElementSet, entrySet, equals, hashCode, isEmpty, remove, removeAll, retainAll, setCount, setCount, size, 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, spliterator, stream, toArray, toArray, toArray
-
Methods inherited from interface com.google.common.collect.Multiset
containsAll
-
-
-
-
Method Detail
-
entryIterator
java.util.Iterator<Multiset.Entry<K>> entryIterator()
- Specified by:
entryIterator
in classAbstractMultiset<K>
-
distinctElements
int distinctElements()
- Specified by:
distinctElements
in classAbstractMultiset<K>
-
createEntrySet
java.util.Set<Multiset.Entry<K>> createEntrySet()
- Overrides:
createEntrySet
in classAbstractMultiset<K>
-
contains
public boolean contains(@Nullable java.lang.Object element)
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.
-
iterator
public java.util.Iterator<K> 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
public int count(@Nullable java.lang.Object element)
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.
-
remove
public int remove(@Nullable java.lang.Object element, int occurrences)
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 interfacejava.util.Collection<K>
- Overrides:
clear
in classAbstractMultiset<K>
-
elementSet
public java.util.Set<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
-
-