java.lang.Object | ||
↳ | org.apache.commons.collections.collection.SynchronizedCollection | |
↳ | org.apache.commons.collections.bag.SynchronizedBag |
Known Direct Subclasses |
Decorates another Bag
to synchronize its behaviour
for a multi-threaded environment.
Methods are synchronized, then forwarded to the decorated bag. Iterators must be separately synchronized around the loop.
This class is Serializable from Commons Collections 3.1.
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.apache.commons.collections.collection.SynchronizedCollection
|
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructor that wraps (not copies).
| |||||||||||
Constructor that wraps (not copies).
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds
nCopies copies of the specified object to the Bag. | |||||||||||
Factory method to create a synchronized bag.
| |||||||||||
Returns the number of occurrences (cardinality) of the given
object currently in the bag.
| |||||||||||
Removes
nCopies copies of the specified object from the Bag. | |||||||||||
Returns a
Set of unique elements in the Bag. |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Gets the bag being decorated.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.apache.commons.collections.collection.SynchronizedCollection
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.lang.Iterable
| |||||||||||
From interface
java.util.Collection
| |||||||||||
From interface
org.apache.commons.collections.Bag
|
Constructor that wraps (not copies).
bag | the bag to decorate, must not be null |
---|
IllegalArgumentException | if bag is null |
---|
Constructor that wraps (not copies).
bag | the bag to decorate, must not be null |
---|---|
lock | the lock to use, must not be null |
IllegalArgumentException | if bag is null |
---|
Adds nCopies
copies of the specified object to the Bag.
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 nCopies
.
object | the object to add |
---|---|
count | the number of copies to add |
true
if the object was not already in the uniqueSet
Factory method to create a synchronized bag.
bag | the bag to decorate, must not be null |
---|
IllegalArgumentException | if bag is null |
---|
Returns the number of occurrences (cardinality) of the given object currently in the bag. If the object does not exist in the bag, return 0.
object | the object to search for |
---|
Removes nCopies
copies of the specified object from the Bag.
If the number of copies to remove is greater than the actual number of copies in the Bag, no error is thrown.
object | the object to remove |
---|---|
count | the number of copies to remove |
true
if this call changed the collection