public class MultiSetUtils extends Object
MultiSet
instances.Modifier and Type | Field and Description |
---|---|
static MultiSet |
EMPTY_MULTISET
An empty unmodifiable multiset.
|
Modifier and Type | Method and Description |
---|---|
static <E> MultiSet<E> |
emptyMultiSet()
Get an empty
MultiSet . |
static <E> MultiSet<E> |
predicatedMultiSet(MultiSet<E> multiset,
Predicate<? super E> predicate)
Returns a predicated (validating) multiset backed by the given multiset.
|
static <E> MultiSet<E> |
synchronizedMultiSet(MultiSet<E> multiset)
Returns a synchronized (thread-safe) multiset backed by the given multiset.
|
static <E> MultiSet<E> |
unmodifiableMultiSet(MultiSet<? extends E> multiset)
Returns an unmodifiable view of the given multiset.
|
public static final MultiSet EMPTY_MULTISET
public static <E> MultiSet<E> synchronizedMultiSet(MultiSet<E> multiset)
It is imperative that the user manually synchronize on the returned multiset when iterating over it:
MultiSet multiset = MultiSetUtils.synchronizedMultiSet(new HashMultiSet()); ... synchronized(multiset) { Iterator i = multiset.iterator(); // Must be in synchronized block while (i.hasNext()) foo(i.next()); } }Failure to follow this advice may result in non-deterministic behavior.
E
- the element typemultiset
- the multiset to synchronize, must not be nullNullPointerException
- if the MultiSet is nullpublic static <E> MultiSet<E> unmodifiableMultiSet(MultiSet<? extends E> multiset)
UnsupportedOperationException
.E
- the element typemultiset
- the multiset whose unmodifiable view is to be returned, must not be nullNullPointerException
- if the MultiSet is nullpublic static <E> MultiSet<E> predicatedMultiSet(MultiSet<E> multiset, Predicate<? super E> predicate)
Only objects that pass the test in the given predicate can be added to the multiset. Trying to add an invalid object results in an IllegalArgumentException. It is important not to use the original multiset after invoking this method, as it is a backdoor for adding invalid objects.
E
- the element typemultiset
- the multiset to predicate, must not be nullpredicate
- the predicate for the multiset, must not be nullNullPointerException
- if the MultiSet or Predicate is nullpublic static <E> MultiSet<E> emptyMultiSet()
MultiSet
.E
- the element typeCopyright © 2001–2018 The Apache Software Foundation. All rights reserved.