Top Description Inners Fields Constructors Methods
org.apache.commons.collections4.multiset

public Class SynchronizedMultiSet<E>

extends SynchronizedCollection<E>
implements MultiSet<E>
Class Inheritance
All Implemented Interfaces
org.apache.commons.collections4.MultiSet, java.util.Collection, java.lang.Iterable
Type Parameters
<E>
the type held in the multiset
Imports
java.util.Set, org.apache.commons.collections4.MultiSet, org.apache.commons.collections4.collection.SynchronizedCollection

Decorates another 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.

Since
4.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
SynchronizedMultiSet.SynchronizedSet<T>

Synchronized Set for the MultiSet class.

Field Summary

Modifier and TypeField and Description
private static final long
Inherited from org.apache.commons.collections4.collection.SynchronizedCollection:
lock

Constructor Summary

AccessConstructor and Description
protected
SynchronizedMultiSet(final MultiSet<E>
the multiset to decorate, must not be null
multiset
)

Constructor that wraps (not copies).

protected
SynchronizedMultiSet(final MultiSet<E>
the multiset to decorate, must not be null
multiset
,
final Object
the lock to use, must not be null
lock
)

Constructor that wraps (not copies).

Method Summary

Modifier and TypeMethod and Description
public int
add(final E
the object to add
object
,
final int
the number of occurrences to add, may be zero, in which case no change is made to the multiset
count
)

Implements org.apache.commons.collections4.MultiSet.add.

Adds a number of occurrences of the specified object to the MultiSet.
protected MultiSet<E>

Returns:

the decorated multiset
decorated
()

Overrides org.apache.commons.collections4.collection.SynchronizedCollection.decorated.

Gets the multiset being decorated.
public Set<MultiSet.Entry<E>>
entrySet()

Implements org.apache.commons.collections4.MultiSet.entrySet.

Returns a Set of all entries contained in the MultiSet.
public boolean
equals(final Object
the object to compare to
object
)

Overrides org.apache.commons.collections4.collection.SynchronizedCollection.equals.

Implements org.apache.commons.collections4.MultiSet.equals, java.util.Collection.equals.

Compares this MultiSet to another object.
public int
getCount(final Object
the object to search for
object
)

Implements org.apache.commons.collections4.MultiSet.getCount.

Returns the number of occurrences of the given object currently in the MultiSet.
public int
public int
remove(final Object
the object to remove
object
,
final int
the number of occurrences to remove, may be zero, in which case no change is made to the multiset
count
)

Implements org.apache.commons.collections4.MultiSet.remove.

Removes a number of occurrences of the specified object from the MultiSet.
public int
setCount(final E
the object to update
object
,
final int
the number of occurrences of the object
count
)

Implements org.apache.commons.collections4.MultiSet.setCount.

Sets the number of occurrences of the specified object in the MultiSet to the given count.
public static <
the type of the elements in the multiset
E
>
SynchronizedMultiSet<E>

Returns:

a new synchronized MultiSet
synchronizedMultiSet
(final MultiSet<E>
the multiset to decorate, must not be null
multiset
)

Factory method to create a synchronized multiset.

public Set<E>
uniqueSet()

Implements org.apache.commons.collections4.MultiSet.uniqueSet.

Returns a Set of unique elements in the MultiSet.
Inherited from org.apache.commons.collections4.collection.SynchronizedCollection:
addaddAllclearcontainscontainsAllisEmptyiteratorremoveremoveAllremoveIfretainAllsizesynchronizedCollectiontoArraytoArraytoString

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.collections4.collection.SynchronizedCollection.serialVersionUID.

Serialization version

Constructor Detail

SynchronizedMultiSetback to summary
protected SynchronizedMultiSet(final MultiSet<E> multiset)

Constructor that wraps (not copies).

Parameters
multiset:MultiSet<E>

the multiset to decorate, must not be null

Exceptions
NullPointerException:
if multiset is null
SynchronizedMultiSetback to summary
protected SynchronizedMultiSet(final MultiSet<E> multiset, final Object lock)

Constructor that wraps (not copies).

Parameters
multiset:MultiSet<E>

the multiset to decorate, must not be null

lock:Object

the lock to use, must not be null

Exceptions
NullPointerException:
if multiset or lock is null

Method Detail

addback to summary
public int add(final E object, final int count)

Implements org.apache.commons.collections4.MultiSet.add.

Doc from org.apache.commons.collections4.MultiSet.add.

Adds a number of occurrences of the specified object to the MultiSet.

If the object is already in the uniqueSet() then increment its count as reported by getCount(Object). Otherwise add it to the uniqueSet() and report its count as occurrences.

Parameters
object:E

the object to add

count:int

the number of occurrences to add, may be zero, in which case no change is made to the multiset

Returns:int

the number of occurrences of the object in the multiset before this operation; possibly zero

Annotations
@Override
decoratedback to summary
protected MultiSet<E> decorated()

Overrides org.apache.commons.collections4.collection.SynchronizedCollection.decorated.

Gets the multiset being decorated.

Returns:MultiSet<E>

the decorated multiset

Annotations
@Override
entrySetback to summary
public Set<MultiSet.Entry<E>> entrySet()

Implements org.apache.commons.collections4.MultiSet.entrySet.

Doc from org.apache.commons.collections4.MultiSet.entrySet.

Returns a Set 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.

Returns:Set<MultiSet.Entry<E>>

the Set of MultiSet entries

Annotations
@Override
equalsback to summary
public boolean equals(final Object object)

Overrides org.apache.commons.collections4.collection.SynchronizedCollection.equals.

Implements org.apache.commons.collections4.MultiSet.equals, java.util.Collection.equals.

Doc from org.apache.commons.collections4.MultiSet.equals.

Compares 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.

Parameters
object:Object

the object to compare to

Returns:boolean

true if equal

Annotations
@Override
getCountback to summary
public int getCount(final Object object)

Implements org.apache.commons.collections4.MultiSet.getCount.

Doc from org.apache.commons.collections4.MultiSet.getCount.

Returns the number of occurrences of the given object currently in the MultiSet. If the object does not exist in the multiset, return 0.

Parameters
object:Object

the object to search for

Returns:int

the number of occurrences of the object, zero if not found

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides org.apache.commons.collections4.collection.SynchronizedCollection.hashCode.

Implements org.apache.commons.collections4.MultiSet.hashCode, java.util.Collection.hashCode.

Doc from org.apache.commons.collections4.MultiSet.hashCode.

Gets 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()) ^ noOccurances).

Returns:int

the hash code of the MultiSet

Annotations
@Override
removeback to summary
public int remove(final Object object, final int count)

Implements org.apache.commons.collections4.MultiSet.remove.

Doc from org.apache.commons.collections4.MultiSet.remove.

Removes 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.

Parameters
object:Object

the object to remove

count:int

the number of occurrences to remove, may be zero, in which case no change is made to the multiset

Returns:int

the number of occurrences of the object in the multiset before the operation; possibly zero

Annotations
@Override
setCountback to summary
public int setCount(final E object, final int count)

Implements org.apache.commons.collections4.MultiSet.setCount.

Doc from org.apache.commons.collections4.MultiSet.setCount.

Sets 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 uniqueSet().

Parameters
object:E

the object to update

count:int

the number of occurrences of the object

Returns:int

the number of occurrences of the object before this operation, zero if the object was not contained in the multiset

Annotations
@Override
synchronizedMultiSetback to summary
public static <E> SynchronizedMultiSet<E> synchronizedMultiSet(final MultiSet<E> multiset)

Factory method to create a synchronized multiset.

Parameters
<E>
the type of the elements in the multiset
multiset:MultiSet<E>

the multiset to decorate, must not be null

Returns:SynchronizedMultiSet<E>

a new synchronized MultiSet

Exceptions
NullPointerException:
if multiset is null
uniqueSetback to summary
public Set<E> uniqueSet()

Implements org.apache.commons.collections4.MultiSet.uniqueSet.

Doc from org.apache.commons.collections4.MultiSet.uniqueSet.

Returns a Set of unique elements in the MultiSet.

Uniqueness constraints are the same as those in java.util.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.

Returns:Set<E>

the Set of unique MultiSet elements

Annotations
@Override
org.apache.commons.collections4.multiset back to summary

pack-priv Class SynchronizedMultiSet.SynchronizedSet<T>

extends SynchronizedCollection<T>
implements Set<T>
Class Inheritance
All Implemented Interfaces
java.util.Set, java.util.Collection, java.lang.Iterable

Synchronized Set for the MultiSet class.

Field Summary

Modifier and TypeField and Description
private static final long
Inherited from org.apache.commons.collections4.collection.SynchronizedCollection:
lock

Constructor Summary

AccessConstructor and Description
pack-priv
SynchronizedSet(final Set<T>
the set to decorate
set
,
final Object
the lock to use, shared with the multiset
lock
)

Constructor.

Method Summary

Inherited from org.apache.commons.collections4.collection.SynchronizedCollection:
addaddAllclearcontainscontainsAlldecoratedequalshashCodeisEmptyiteratorremoveremoveAllremoveIfretainAllsizesynchronizedCollectiontoArraytoArraytoString

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.collections4.collection.SynchronizedCollection.serialVersionUID.

Serialization version

Constructor Detail

SynchronizedSetback to summary
pack-priv SynchronizedSet(final Set<T> set, final Object lock)

Constructor.

Parameters
set:Set<T>

the set to decorate

lock:Object

the lock to use, shared with the multiset