@GwtCompatible public final class Multisets extends Object
Multiset instances.
See the Guava User Guide article on Multisets.
| Modifier and Type | Method and Description |
|---|---|
static boolean |
containsOccurrences(Multiset<?> superMultiset,
Multiset<?> subMultiset)
Returns
true if subMultiset.count(o) <= superMultiset.count(o) for all o. |
static boolean |
removeOccurrences(Multiset<?> multisetToModify,
Iterable<?> occurrencesToRemove)
For each occurrence of an element
e in occurrencesToRemove, removes one
occurrence of e in multisetToModify. |
static boolean |
removeOccurrences(Multiset<?> multisetToModify,
Multiset<?> occurrencesToRemove)
For each occurrence of an element
e in occurrencesToRemove, removes one
occurrence of e in multisetToModify. |
static boolean |
retainOccurrences(Multiset<?> multisetToModify,
Multiset<?> multisetToRetain)
Modifies
multisetToModify so that its count for an element e is at most multisetToRetain.count(e). |
static <T,E,M extends Multiset<E>> |
toMultiset(java.util.function.Function<? super T,E> elementFunction,
java.util.function.ToIntFunction<? super T> countFunction,
java.util.function.Supplier<M> multisetSupplier)
Returns a
Collector that accumulates elements into a multiset created via the specified
Supplier, whose elements are the result of applying elementFunction to the
inputs, with counts equal to the result of applying countFunction to the inputs. |
public static <T,E,M extends Multiset<E>> java.util.stream.Collector<T,?,M> toMultiset(java.util.function.Function<? super T,E> elementFunction, java.util.function.ToIntFunction<? super T> countFunction, java.util.function.Supplier<M> multisetSupplier)
Collector that accumulates elements into a multiset created via the specified
Supplier, whose elements are the result of applying elementFunction to the
inputs, with counts equal to the result of applying countFunction to the inputs.
Elements are added in encounter order.
If the mapped elements contain duplicates (according to Object.equals(java.lang.Object)), the element
will be added more than once, with the count summed over all appearances of the element.
Note that stream.collect(toMultiset(function, e -> 1, supplier)) is equivalent to
stream.map(function).collect(Collectors.toCollection(supplier)).
@CanIgnoreReturnValue public static boolean containsOccurrences(Multiset<?> superMultiset, Multiset<?> subMultiset)
true if subMultiset.count(o) <= superMultiset.count(o) for all o.@CanIgnoreReturnValue public static boolean retainOccurrences(Multiset<?> multisetToModify, Multiset<?> multisetToRetain)
multisetToModify so that its count for an element e is at most multisetToRetain.count(e).
To be precise, multisetToModify.count(e) is set to Math.min(multisetToModify.count(e), multisetToRetain.count(e)). This is similar to intersection (multisetToModify, multisetToRetain),
but mutates multisetToModify instead of returning a view.
In contrast, multisetToModify.retainAll(multisetToRetain) keeps all occurrences of
elements that appear at all in multisetToRetain, and deletes all occurrences of all
other elements.
true if multisetToModify was changed as a result of this operation@CanIgnoreReturnValue public static boolean removeOccurrences(Multiset<?> multisetToModify, Iterable<?> occurrencesToRemove)
e in occurrencesToRemove, removes one
occurrence of e in multisetToModify.
Equivalently, this method modifies multisetToModify so that multisetToModify.count(e) is set to Math.max(0, multisetToModify.count(e) -
Iterables.frequency(occurrencesToRemove, e)).
This is not the same as multisetToModify. removeAll(occurrencesToRemove), which removes all occurrences of elements that appear
in occurrencesToRemove. However, this operation is equivalent to, albeit
sometimes more efficient than, the following:
for (E e : occurrencesToRemove) {
multisetToModify.remove(e);
}
true if multisetToModify was changed as a result of this operationMultiset)@CanIgnoreReturnValue public static boolean removeOccurrences(Multiset<?> multisetToModify, Multiset<?> occurrencesToRemove)
e in occurrencesToRemove, removes one
occurrence of e in multisetToModify.
Equivalently, this method modifies multisetToModify so that multisetToModify.count(e) is set to Math.max(0, multisetToModify.count(e) -
occurrencesToRemove.count(e)).
This is not the same as multisetToModify. removeAll(occurrencesToRemove), which removes all occurrences of elements that appear
in occurrencesToRemove. However, this operation is equivalent to, albeit
sometimes more efficient than, the following:
for (E e : occurrencesToRemove) {
multisetToModify.remove(e);
}
true if multisetToModify was changed as a result of this operationIterable was present)Copyright © 2007-2020. All Rights Reserved.