Class SynchronizedMultiSet<E>
- Type Parameters:
- E- the type held in the multiset.
- All Implemented Interfaces:
- Serializable,- Iterable<E>,- Collection<E>,- MultiSet<E>
MultiSet to synchronize its behavior
 for a multithreaded environment.
 Methods are synchronized, then forwarded to the decorated multiset. Iterators must be separately synchronized around the loop.
- Since:
- 4.1
- See Also:
- 
Nested Class SummaryNested classes/interfaces inherited from interface org.apache.commons.collections4.MultiSetMultiSet.Entry<E>
- 
Field SummaryFields inherited from class org.apache.commons.collections4.collection.SynchronizedCollectionlock
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedSynchronizedMultiSet(MultiSet<E> multiset) Constructor that wraps (not copies).protectedSynchronizedMultiSet(MultiSet<E> multiset, Object lock) Constructor that wraps (not copies).
- 
Method SummaryModifier and TypeMethodDescriptionintAdds a number of occurrences of the specified object to the MultiSet.Gets the multiset being decorated.entrySet()Returns aSetof all entries contained in the MultiSet.booleanCompares this MultiSet to another object.intGets the number of occurrences of the given object currently in the MultiSet.inthashCode()Gets a hash code for the MultiSet compatible with the definition of equals.intRemoves a number of occurrences of the specified object from the MultiSet.intSets 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.Returns aSetof unique elements in the MultiSet.Methods inherited from class org.apache.commons.collections4.collection.SynchronizedCollectionadd, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, removeIf, retainAll, size, synchronizedCollection, toArray, toArray, toStringMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.CollectionaddAll, clear, contains, isEmpty, parallelStream, removeIf, spliterator, stream, toArray, toArray
- 
Constructor Details- 
SynchronizedMultiSetConstructor that wraps (not copies).- Parameters:
- multiset- the multiset to decorate, must not be null
- Throws:
- NullPointerException- if multiset is null
 
- 
SynchronizedMultiSetConstructor that wraps (not copies).- Parameters:
- multiset- the multiset to decorate, must not be null
- lock- the lock to use, must not be null
- Throws:
- NullPointerException- if multiset or lock is null
 
 
- 
- 
Method Details- 
synchronizedMultiSetFactory method to create a synchronized multiset.- Type Parameters:
- E- the type of the elements in the multiset
- Parameters:
- multiset- the multiset to decorate, must not be null
- Returns:
- a new synchronized MultiSet
- Throws:
- NullPointerException- if multiset is null
 
- 
addDescription copied from interface:MultiSetAdds a number of occurrences of the specified object to the MultiSet.If the object is already in the MultiSet.uniqueSet()then increment its count as reported byMultiSet.getCount(Object). Otherwise, add it to theMultiSet.uniqueSet()and report its count asoccurrences.
- 
decorated
- 
entrySet
- 
equalsDescription copied from interface:MultiSetCompares this MultiSet to another object.This MultiSet equals another object if it is also a MultiSet that contains the same number of occurrences of the same elements. - Specified by:
- equalsin interface- Collection<E>
- Specified by:
- equalsin interface- MultiSet<E>
- Overrides:
- equalsin class- SynchronizedCollection<E>
- Parameters:
- object- the object to compare to
- Returns:
- true if equal
 
- 
getCountDescription copied from interface:MultiSetGets the number of occurrences of the given object currently in the MultiSet. If the object does not exist in the multiset, return 0.
- 
hashCodeDescription copied from interface:MultiSetGets a hash code for the MultiSet compatible with the definition of equals. The hash code is defined as the sum total of a hash code for each element. The per element hash code is defined as(e==null ? 0 : e.hashCode()) ^ noOccurrences).- Specified by:
- hashCodein interface- Collection<E>
- Specified by:
- hashCodein interface- MultiSet<E>
- Overrides:
- hashCodein class- SynchronizedCollection<E>
- Returns:
- the hash code of the MultiSet
 
- 
removeDescription copied from interface:MultiSetRemoves a number of occurrences of the specified object from the MultiSet.If 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. 
- 
setCountDescription copied from interface:MultiSetSets the number of occurrences of the specified object in the MultiSet to the given count.If the provided count is zero, the object will be removed from the MultiSet.uniqueSet().
- 
uniqueSetDescription copied from interface:MultiSetReturns aSetof 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. 
 
-