com.google.common.collect
Class Multisets

java.lang.Object
  extended by com.google.common.collect.Multisets

public final class Multisets
extends Object

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

Since:
2010.01.04 stable (imported from Google Collections Library)
Author:
Kevin Bourrillion, Mike Bostock

Method Summary
static
<E> Multiset.Entry<E>
immutableEntry(E e, int n)
          Returns an immutable multiset entry with the specified element and count.
static
<E> Multiset<E>
intersection(Multiset<E> multiset1, Multiset<?> multiset2)
          Returns an unmodifiable view of the intersection of two multisets.
static
<E> Multiset<E>
unmodifiableMultiset(Multiset<? extends E> multiset)
          Returns an unmodifiable view of the specified multiset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

unmodifiableMultiset

public static <E> Multiset<E> unmodifiableMultiset(Multiset<? extends E> multiset)
Returns an unmodifiable view of the specified multiset. Query operations on the returned multiset "read through" to the specified multiset, and attempts to modify the returned multiset result in an UnsupportedOperationException.

The returned multiset will be serializable if the specified multiset is serializable.

Parameters:
multiset - the multiset for which an unmodifiable view is to be generated
Returns:
an unmodifiable view of the multiset

immutableEntry

public static <E> Multiset.Entry<E> immutableEntry(@Nullable
                                                   E e,
                                                   int n)
Returns an immutable multiset entry with the specified element and count.

Parameters:
e - the element to be associated with the returned entry
n - the count to be associated with the returned entry
Throws:
IllegalArgumentException - if n is negative

intersection

public static <E> Multiset<E> intersection(Multiset<E> multiset1,
                                           Multiset<?> multiset2)
Returns an unmodifiable view of the intersection of two multisets. An element's count in the multiset is the smaller of its counts in the two backing multisets. The iteration order of the returned multiset matches the element set of multiset1, with repeated occurrences of the same element appearing consecutively.

Results are undefined if multiset1 and multiset2 are based on different equivalence relations (as HashMultiset and TreeMultiset are).

Since:
2010.01.04 tentative