public class BagUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static Bag |
EMPTY_BAG
An empty unmodifiable bag.
|
static Bag |
EMPTY_SORTED_BAG
An empty unmodifiable sorted bag.
|
Constructor and Description |
---|
BagUtils()
Instantiation of BagUtils is not intended or required.
|
Modifier and Type | Method and Description |
---|---|
static Bag |
predicatedBag(Bag bag,
Predicate predicate)
Returns a predicated (validating) bag backed by the given bag.
|
static SortedBag |
predicatedSortedBag(SortedBag bag,
Predicate predicate)
Returns a predicated (validating) sorted bag backed by the given sorted bag.
|
static Bag |
synchronizedBag(Bag bag)
Returns a synchronized (thread-safe) bag backed by the given bag.
|
static SortedBag |
synchronizedSortedBag(SortedBag bag)
Returns a synchronized (thread-safe) sorted bag backed by the given
sorted bag.
|
static Bag |
transformedBag(Bag bag,
Transformer transformer)
Returns a transformed bag backed by the given bag.
|
static SortedBag |
transformedSortedBag(SortedBag bag,
Transformer transformer)
Returns a transformed sorted bag backed by the given bag.
|
static Bag |
typedBag(Bag bag,
java.lang.Class type)
Returns a typed bag backed by the given bag.
|
static SortedBag |
typedSortedBag(SortedBag bag,
java.lang.Class type)
Returns a typed sorted bag backed by the given bag.
|
static Bag |
unmodifiableBag(Bag bag)
Returns an unmodifiable view of the given bag.
|
static SortedBag |
unmodifiableSortedBag(SortedBag bag)
Returns an unmodifiable view of the given sorted bag.
|
public static final Bag EMPTY_BAG
public static final Bag EMPTY_SORTED_BAG
public BagUtils()
public static Bag synchronizedBag(Bag 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 nulljava.lang.IllegalArgumentException
- if the Bag is nullpublic static Bag unmodifiableBag(Bag bag)
UnsupportedOperationException
.bag
- the bag whose unmodifiable view is to be returned, must not be nulljava.lang.IllegalArgumentException
- if the Bag is nullpublic static Bag predicatedBag(Bag bag, Predicate predicate)
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 nullpredicate
- the predicate for the bag, must not be nulljava.lang.IllegalArgumentException
- if the Bag or Predicate is nullpublic static Bag typedBag(Bag bag, java.lang.Class type)
Only objects of the specified type can be added to the bag.
bag
- the bag to limit to a specific type, must not be nulltype
- the type of objects which may be added to the bagpublic static Bag transformedBag(Bag bag, Transformer transformer)
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 nulltransformer
- the transformer for the bag, must not be nulljava.lang.IllegalArgumentException
- if the Bag or Transformer is nullpublic static SortedBag synchronizedSortedBag(SortedBag 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 nulljava.lang.IllegalArgumentException
- if the SortedBag is nullpublic static SortedBag unmodifiableSortedBag(SortedBag bag)
UnsupportedOperationException
.bag
- the bag whose unmodifiable view is to be returned, must not be nulljava.lang.IllegalArgumentException
- if the SortedBag is nullpublic static SortedBag predicatedSortedBag(SortedBag bag, Predicate predicate)
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 nullpredicate
- the predicate for the bag, must not be nulljava.lang.IllegalArgumentException
- if the SortedBag or Predicate is nullpublic static SortedBag typedSortedBag(SortedBag bag, java.lang.Class type)
Only objects of the specified type can be added to the bag.
bag
- the bag to limit to a specific type, must not be nulltype
- the type of objects which may be added to the bagpublic static SortedBag transformedSortedBag(SortedBag bag, Transformer transformer)
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 nulltransformer
- the transformer for the bag, must not be nulljava.lang.IllegalArgumentException
- if the Bag or Transformer is nullCopyright © 2010 - 2020 Adobe. All Rights Reserved