| java.lang.Object org.apache.commons.collections.BagUtils
BagUtils | public class BagUtils (Code) | | Provides utility methods and decorators for
Bag and
SortedBag instances.
since: Commons Collections 2.1 version: $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $ author: Paul Jack author: Stephen Colebourne author: Andrew Freeman author: Matthew Hawthorne |
Constructor Summary | |
public | BagUtils() Instantiation of BagUtils is not intended or required. |
EMPTY_BAG | final public static Bag EMPTY_BAG(Code) | | An empty unmodifiable bag.
|
EMPTY_SORTED_BAG | final public static Bag EMPTY_SORTED_BAG(Code) | | An empty unmodifiable sorted bag.
|
BagUtils | public BagUtils()(Code) | | Instantiation of BagUtils is not intended or required.
However, some tools require an instance to operate.
|
predicatedBag | public static Bag predicatedBag(Bag bag, Predicate predicate)(Code) | | 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.
Parameters: bag - the bag to predicate, must not be null Parameters: predicate - the predicate for the bag, must not be null a predicated bag backed by the given bag throws: IllegalArgumentException - if the Bag or Predicate is null |
predicatedSortedBag | public static SortedBag predicatedSortedBag(SortedBag bag, Predicate predicate)(Code) | | 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.
Parameters: bag - the sorted bag to predicate, must not be null Parameters: predicate - the predicate for the bag, must not be null a predicated bag backed by the given bag throws: IllegalArgumentException - if the SortedBag or Predicate is null |
synchronizedBag | public static Bag synchronizedBag(Bag bag)(Code) | | 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.
Parameters: bag - the bag to synchronize, must not be null a synchronized bag backed by that bag throws: IllegalArgumentException - if the Bag is null |
synchronizedSortedBag | public static SortedBag synchronizedSortedBag(SortedBag bag)(Code) | | 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.
Parameters: bag - the bag to synchronize, must not be null a synchronized bag backed by that bag throws: IllegalArgumentException - if the SortedBag is null |
transformedBag | public static Bag transformedBag(Bag bag, Transformer transformer)(Code) | | 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.
Parameters: bag - the bag to predicate, must not be null Parameters: transformer - the transformer for the bag, must not be null a transformed bag backed by the given bag throws: IllegalArgumentException - if the Bag or Transformer is null |
transformedSortedBag | public static SortedBag transformedSortedBag(SortedBag bag, Transformer transformer)(Code) | | 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.
Parameters: bag - the bag to predicate, must not be null Parameters: transformer - the transformer for the bag, must not be null a transformed bag backed by the given bag throws: IllegalArgumentException - if the Bag or Transformer is null |
typedBag | public static Bag typedBag(Bag bag, Class type)(Code) | | Returns a typed bag backed by the given bag.
Only objects of the specified type can be added to the bag.
Parameters: bag - the bag to limit to a specific type, must not be null Parameters: type - the type of objects which may be added to the bag a typed bag backed by the specified bag |
typedSortedBag | public static SortedBag typedSortedBag(SortedBag bag, Class type)(Code) | | Returns a typed sorted bag backed by the given bag.
Only objects of the specified type can be added to the bag.
Parameters: bag - the bag to limit to a specific type, must not be null Parameters: type - the type of objects which may be added to the bag a typed bag backed by the specified bag |
unmodifiableBag | public static Bag unmodifiableBag(Bag bag)(Code) | | Returns an unmodifiable view of the given bag. Any modification
attempts to the returned bag will raise an
UnsupportedOperationException .
Parameters: bag - the bag whose unmodifiable view is to be returned, must not be null an unmodifiable view of that bag throws: IllegalArgumentException - if the Bag is null |
unmodifiableSortedBag | public static SortedBag unmodifiableSortedBag(SortedBag bag)(Code) | | Returns an unmodifiable view of the given sorted bag. Any modification
attempts to the returned bag will raise an
UnsupportedOperationException .
Parameters: bag - the bag whose unmodifiable view is to be returned, must not be null an unmodifiable view of that bag throws: IllegalArgumentException - if the SortedBag is null |
|
|