Top Description Inners Constructors Methods
com.google.common.collect

public final Class Multisets

extends Object
Class Inheritance
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkNotNull, com.google.common.collect.CollectPreconditions.checkNonnegative, .CollectPreconditions.checkRemove, java.util.Objects.requireNonNull

Provides static utility methods for creating and working with Multiset instances.

See the Guava User Guide article on Multisets.

Authors
Kevin Bourrillion, Mike Bostock, Louis Wasserman
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv abstract static class
Multisets.AbstractEntry<E extends @Nullable Object>

Implementation of the equals, hashCode, and toString methods of Multiset.Entry.

private static class
pack-priv abstract static class
pack-priv abstract static class
private static class
pack-priv static class
pack-priv static class
pack-priv static class
private abstract static class
Multisets.ViewMultiset<E extends @Nullable Object>

An AbstractMultiset with additional default implementations, some of them linear-time implementations in terms of elementSet and entrySet.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static <E extends @Nullable Object> boolean
addAllImpl(Multiset<E> self, Collection<? extends E> elements)

An implementation of Multiset#addAll.

private static <E extends @Nullable Object> boolean
addAllImpl(Multiset<E> self, Multiset<? extends E> elements)

A specialization of addAllImpl for when elements is itself a Multiset.

pack-priv static <T extends @Nullable Object> Multiset<T>
cast(Iterable<T> iterable)

Used to avoid http://bugs.sun.com/view_bug.do?bug_id=6558557

public static boolean
containsOccurrences(Multiset<?> superMultiset, Multiset<?> subMultiset)

Returns true if subMultiset.count(o) <= superMultiset.count(o) for all o.

public static <E> ImmutableMultiset<E>
copyHighestCountFirst(Multiset<E> multiset)

Returns a copy of multiset as an ImmutableMultiset whose iteration order puts the highest count first, with ties broken by the iteration order of the original multiset.

public static <E extends @Nullable Object> Multiset<E>
difference(final Multiset<E> multiset1, final Multiset<?> multiset2)

Returns an unmodifiable view of the difference of two multisets.

pack-priv static <E extends @Nullable Object> Iterator<E>
pack-priv static boolean
equalsImpl(Multiset<?> multiset, Object object)

An implementation of Multiset#equals.

public static <E extends @Nullable Object> Multiset<E>
filter(Multiset<E> unfiltered, Predicate<? super E> predicate)

Returns a view of the elements of unfiltered that satisfy a predicate.

public static <E extends @Nullable Object> Multiset.Entry<E>
immutableEntry(E
the element to be associated with the returned entry
e
,
int
the count to be associated with the returned entry
n
)

Returns an immutable multiset entry with the specified element and count.

pack-priv static int
inferDistinctElements(Iterable<?> elements)

Returns the expected number of distinct elements given the specified elements.

public static <E extends @Nullable Object> Multiset<E>
intersection(final Multiset<E> multiset1, final Multiset<?> multiset2)

Returns an unmodifiable view of the intersection of two multisets.

pack-priv static <E extends @Nullable Object> Iterator<E>
iteratorImpl(Multiset<E> multiset)

An implementation of Multiset#iterator.

pack-priv static int
linearTimeSizeImpl(Multiset<?> multiset)

An implementation of Multiset#size.

pack-priv static boolean
removeAllImpl(Multiset<?> self, Collection<?> elementsToRemove)

An implementation of Multiset#removeAll.

public static boolean

Returns:

true if multisetToModify was changed as a result of this operation
removeOccurrences
(Multiset<?> multisetToModify, Iterable<?> occurrencesToRemove)

For each occurrence of an element e in occurrencesToRemove, removes one occurrence of e in multisetToModify.

public static boolean

Returns:

true if multisetToModify was changed as a result of this operation
removeOccurrences
(Multiset<?> multisetToModify, Multiset<?> occurrencesToRemove)

For each occurrence of an element e in occurrencesToRemove, removes one occurrence of e in multisetToModify.

pack-priv static boolean
retainAllImpl(Multiset<?> self, Collection<?> elementsToRetain)

An implementation of Multiset#retainAll.

public static boolean

Returns:

true if multisetToModify was changed as a result of this operation
retainOccurrences
(Multiset<?> multisetToModify, Multiset<?> multisetToRetain)

Modifies multisetToModify so that its count for an element e is at most multisetToRetain.count(e).

private static <E extends @Nullable Object> boolean
retainOccurrencesImpl(Multiset<E> multisetToModify, Multiset<?> occurrencesToRetain)

Delegate implementation which cares about the element type.

pack-priv static <E extends @Nullable Object> int
setCountImpl(Multiset<E> self, E element, int count)

An implementation of Multiset#setCount(Object, int).

pack-priv static <E extends @Nullable Object> boolean
setCountImpl(Multiset<E> self, E element, int oldCount, int newCount)

An implementation of Multiset#setCount(Object, int, int).

pack-priv static <E extends @Nullable Object> Spliterator<E>
public static <E extends @Nullable Object> Multiset<E>
sum(final Multiset<? extends E> multiset1, final Multiset<? extends E> multiset2)

Returns an unmodifiable view of the sum of two multisets.

public static <T extends @Nullable Object, E extends @Nullable Object, M extends Multiset<E>> Collector<T, ?, M>
toMultiset(Function<? super T, E> elementFunction, ToIntFunction<? super T> countFunction, 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 <E extends @Nullable Object> Multiset<E>
union(final Multiset<? extends E> multiset1, final Multiset<? extends E> multiset2)

Returns an unmodifiable view of the union of two multisets.

public static <E extends @Nullable Object> Multiset<E>

Returns:

an unmodifiable view of the multiset
unmodifiableMultiset
(Multiset<? extends E>
the multiset for which an unmodifiable view is to be generated
multiset
)

Returns an unmodifiable view of the specified multiset.

public static <E> Multiset<E>
unmodifiableMultiset(ImmutableMultiset<E> multiset)

Deprecated no need to use this
Simply returns its argument.
public static <E extends @Nullable Object> SortedMultiset<E>

Returns:

an unmodifiable view of the multiset
unmodifiableSortedMultiset
(SortedMultiset<E>
the sorted multiset for which an unmodifiable view is to be generated
sortedMultiset
)

Returns an unmodifiable view of the specified sorted multiset.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait