Package com.google.common.collect
Class Multisets.FilteredMultiset<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- com.google.common.collect.AbstractMultiset<E>
-
- com.google.common.collect.Multisets.ViewMultiset<E>
-
- com.google.common.collect.Multisets.FilteredMultiset<E>
-
- All Implemented Interfaces:
Multiset<E>
,java.lang.Iterable<E>
,java.util.Collection<E>
- Enclosing class:
- Multisets
private static final class Multisets.FilteredMultiset<E> extends Multisets.ViewMultiset<E>
-
-
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>
-
-
Constructor Summary
Constructors Constructor Description FilteredMultiset(Multiset<E> unfiltered, Predicate<? super E> predicate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
add(E element, int occurrences)
Adds a number of occurrences of an element to this multiset.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<E>
createElementSet()
Creates a new instance of this multiset's element set, which will be returned byAbstractMultiset.elementSet()
.(package private) java.util.Set<Multiset.Entry<E>>
createEntrySet()
(package private) java.util.Iterator<E>
elementIterator()
(package private) java.util.Iterator<Multiset.Entry<E>>
entryIterator()
UnmodifiableIterator<E>
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.Multisets.ViewMultiset
clear, distinctElements, size
-
Methods inherited from class com.google.common.collect.AbstractMultiset
add, addAll, contains, elementSet, entrySet, equals, hashCode, isEmpty, remove, removeAll, retainAll, setCount, setCount, 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, toArray, toArray
-
Methods inherited from interface com.google.common.collect.Multiset
containsAll, forEach, forEachEntry, spliterator
-
-
-
-
Method Detail
-
iterator
public UnmodifiableIterator<E> 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.
-
createElementSet
java.util.Set<E> createElementSet()
Description copied from class:AbstractMultiset
Creates a new instance of this multiset's element set, which will be returned byAbstractMultiset.elementSet()
.- Overrides:
createElementSet
in classAbstractMultiset<E>
-
elementIterator
java.util.Iterator<E> elementIterator()
- Specified by:
elementIterator
in classAbstractMultiset<E>
-
createEntrySet
java.util.Set<Multiset.Entry<E>> createEntrySet()
- Overrides:
createEntrySet
in classAbstractMultiset<E>
-
entryIterator
java.util.Iterator<Multiset.Entry<E>> entryIterator()
- Specified by:
entryIterator
in classAbstractMultiset<E>
-
count
public int count(@CheckForNull 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.- Parameters:
element
- the element to count occurrences of- Returns:
- the number of occurrences of the element in this multiset; possibly zero but never negative
-
add
public int add(E element, int occurrences)
Description copied from interface:Multiset
Adds a number of occurrences of an element to this multiset. Note that ifoccurrences == 1
, this method has the identical effect toMultiset.add(Object)
. This method is functionally equivalent (except in the case of overflow) to the calladdAll(Collections.nCopies(element, occurrences))
, which would presumably perform much more poorly.- Specified by:
add
in interfaceMultiset<E>
- Overrides:
add
in classAbstractMultiset<E>
- Parameters:
element
- the element to add occurrences of; may be null only if explicitly allowed by the implementationoccurrences
- the number of occurrences of the element to add. May be zero, in which case no change will be made.- Returns:
- the count of the element before the operation; possibly zero
-
remove
public int remove(@CheckForNull 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<E>
- Overrides:
remove
in classAbstractMultiset<E>
- 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
-
-