java.lang.Object | |
↳ | org.apache.commons.collections.BagUtils |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
EMPTY_BAG | An empty unmodifiable bag. | ||||||||||
EMPTY_SORTED_BAG | An empty unmodifiable sorted bag. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Instantiation of BagUtils is not intended or required.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns a predicated (validating) bag backed by the given bag.
| |||||||||||
Returns a predicated (validating) sorted bag backed by the given sorted bag.
| |||||||||||
Returns a synchronized (thread-safe) bag backed by the given bag.
| |||||||||||
Returns a synchronized (thread-safe) sorted bag backed by the given
sorted bag.
| |||||||||||
Returns a transformed bag backed by the given bag.
| |||||||||||
Returns a transformed sorted bag backed by the given bag.
| |||||||||||
Returns a typed bag backed by the given bag.
| |||||||||||
Returns a typed sorted bag backed by the given bag.
| |||||||||||
Returns an unmodifiable view of the given bag.
| |||||||||||
Returns an unmodifiable view of the given sorted bag.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Instantiation of BagUtils is not intended or required. However, some tools require an instance to operate.
Returns a predicated (validating) bag backed by the given bag.
Only objects that pass the test in the given predicate can be added to the bag. Trying to add an invalid object results in an IllegalArgumentException. It is important not to use the original bag after invoking this method, as it is a backdoor for adding invalid objects.
bag | the bag to predicate, must not be null |
---|---|
predicate | the predicate for the bag, must not be null |
IllegalArgumentException | if the Bag or Predicate is null |
---|
Returns a predicated (validating) sorted bag backed by the given sorted bag.
Only objects that pass the test in the given predicate can be added to the bag. Trying to add an invalid object results in an IllegalArgumentException. It is important not to use the original bag after invoking this method, as it is a backdoor for adding invalid objects.
bag | the sorted bag to predicate, must not be null |
---|---|
predicate | the predicate for the bag, must not be null |
IllegalArgumentException | if the SortedBag or Predicate is null |
---|
Returns a synchronized (thread-safe) bag backed by the given bag. In order to guarantee serial access, it is critical that all access to the backing bag is accomplished through the returned bag.
It is imperative that the user manually synchronize on the returned bag when iterating over it:
Bag bag = BagUtils.synchronizedBag(new HashBag()); ... synchronized(bag) { Iterator i = bag.iterator(); // Must be in synchronized block while (i.hasNext()) foo(i.next()); } }Failure to follow this advice may result in non-deterministic behavior.
bag | the bag to synchronize, must not be null |
---|
IllegalArgumentException | if the Bag is null |
---|
Returns a synchronized (thread-safe) sorted bag backed by the given sorted bag. In order to guarantee serial access, it is critical that all access to the backing bag is accomplished through the returned bag.
It is imperative that the user manually synchronize on the returned bag when iterating over it:
SortedBag bag = BagUtils.synchronizedSortedBag(new TreeBag()); ... synchronized(bag) { Iterator i = bag.iterator(); // Must be in synchronized block while (i.hasNext()) foo(i.next()); } }Failure to follow this advice may result in non-deterministic behavior.
bag | the bag to synchronize, must not be null |
---|
IllegalArgumentException | if the SortedBag is null |
---|
Returns a transformed bag backed by the given bag.
Each object is passed through the transformer as it is added to the Bag. It is important not to use the original bag after invoking this method, as it is a backdoor for adding untransformed objects.
bag | the bag to predicate, must not be null |
---|---|
transformer | the transformer for the bag, must not be null |
IllegalArgumentException | if the Bag or Transformer is null |
---|
Returns a transformed sorted bag backed by the given bag.
Each object is passed through the transformer as it is added to the Bag. It is important not to use the original bag after invoking this method, as it is a backdoor for adding untransformed objects.
bag | the bag to predicate, must not be null |
---|---|
transformer | the transformer for the bag, must not be null |
IllegalArgumentException | if the Bag or Transformer is null |
---|
Returns a typed bag backed by the given bag.
Only objects of the specified type can be added to the bag.
bag | the bag to limit to a specific type, must not be null |
---|---|
type | the type of objects which may be added to the bag |
Returns a typed sorted bag backed by the given bag.
Only objects of the specified type can be added to the bag.
bag | the bag to limit to a specific type, must not be null |
---|---|
type | the type of objects which may be added to the bag |
Returns an unmodifiable view of the given bag. Any modification
attempts to the returned bag will raise an
UnsupportedOperationException
.
bag | the bag whose unmodifiable view is to be returned, must not be null |
---|
IllegalArgumentException | if the Bag is null |
---|
Returns an unmodifiable view of the given sorted bag. Any modification
attempts to the returned bag will raise an
UnsupportedOperationException
.
bag | the bag whose unmodifiable view is to be returned, must not be null |
---|
IllegalArgumentException | if the SortedBag is null |
---|