public class SynchronizedMultiSet<E> extends SynchronizedCollection<E> implements MultiSet<E>
MultiSet to synchronize its behaviour
for a multi-threaded environment.
Methods are synchronized, then forwarded to the decorated multiset. Iterators must be separately synchronized around the loop.
MultiSet.Entry<E>lock| Modifier | Constructor and Description |
|---|---|
protected |
SynchronizedMultiSet(MultiSet<E> multiset)
Constructor that wraps (not copies).
|
protected |
SynchronizedMultiSet(MultiSet<E> multiset,
Object lock)
Constructor that wraps (not copies).
|
| Modifier and Type | Method and Description |
|---|---|
int |
add(E object,
int count)
Adds a number of occurrences of the specified object to the MultiSet.
|
protected MultiSet<E> |
decorated()
Gets the multiset being decorated.
|
Set<MultiSet.Entry<E>> |
entrySet()
Returns a
Set of all entries contained in the MultiSet. |
boolean |
equals(Object object)
Compares this MultiSet to another object.
|
int |
getCount(Object object)
Returns the number of occurrences of the given object currently
in the MultiSet.
|
int |
hashCode()
Gets a hash code for the MultiSet compatible with the definition of equals.
|
int |
remove(Object object,
int count)
Removes a number of occurrences of the specified object from the MultiSet.
|
int |
setCount(E object,
int count)
Sets the number of occurrences of the specified object in the MultiSet
to the given count.
|
static <E> SynchronizedMultiSet<E> |
synchronizedMultiSet(MultiSet<E> multiset)
Factory method to create a synchronized multiset.
|
Set<E> |
uniqueSet()
Returns a
Set of unique elements in the MultiSet. |
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, synchronizedCollection, toArray, toArray, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitprotected SynchronizedMultiSet(MultiSet<E> multiset)
multiset - the multiset to decorate, must not be nullNullPointerException - if multiset is nullprotected SynchronizedMultiSet(MultiSet<E> multiset, Object lock)
multiset - the multiset to decorate, must not be nulllock - the lock to use, must not be nullNullPointerException - if multiset or lock is nullpublic static <E> SynchronizedMultiSet<E> synchronizedMultiSet(MultiSet<E> multiset)
E - the type of the elements in the multisetmultiset - the multiset to decorate, must not be nullNullPointerException - if multiset is nullprotected MultiSet<E> decorated()
decorated in class SynchronizedCollection<E>public boolean equals(Object object)
MultiSetThis MultiSet equals another object if it is also a MultiSet that contains the same number of occurrences of the same elements.
equals in interface Collection<E>equals in interface MultiSet<E>equals in class SynchronizedCollection<E>object - the object to compare topublic int hashCode()
MultiSet(e==null ? 0 : e.hashCode()) ^ noOccurances).hashCode in interface Collection<E>hashCode in interface MultiSet<E>hashCode in class SynchronizedCollection<E>public int add(E object, int count)
MultiSet
If the object is already in the MultiSet.uniqueSet() then increment its
count as reported by MultiSet.getCount(Object). Otherwise add it to the
MultiSet.uniqueSet() and report its count as occurrences.
public int remove(Object object, int count)
MultiSetIf the number of occurrences to remove is greater than the actual number of occurrences in the multiset, the object will be removed from the multiset.
public int getCount(Object object)
MultiSetpublic int setCount(E object, int count)
MultiSet
If the provided count is zero, the object will be removed from the
MultiSet.uniqueSet().
public Set<E> uniqueSet()
MultiSetSet of unique elements in the MultiSet.
Uniqueness constraints are the same as those in Set.
The returned set is backed by this multiset, so any change to either is immediately reflected in the other. Only removal operations are supported, in which case all occurrences of the element are removed from the backing multiset.
public Set<MultiSet.Entry<E>> entrySet()
MultiSetSet of all entries contained in the MultiSet.
The returned set is backed by this multiset, so any change to either is immediately reflected in the other.
Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.