Modifier and Type | Field and Description |
---|---|
static Bag |
EMPTY_BAG
An empty unmodifiable bag.
|
static Bag |
EMPTY_SORTED_BAG
An empty unmodifiable sorted bag.
|
Modifier and Type | Method and Description |
---|---|
static <E> Bag<E> |
collectionBag(Bag<E> bag)
Returns a bag that complies to the Collection contract, backed by the given bag.
|
static <E> Bag<E> |
emptyBag()
Get an empty
Bag . |
static <E> SortedBag<E> |
emptySortedBag()
Get an empty
SortedBag . |
static <E> Bag<E> |
predicatedBag(Bag<E> bag,
Predicate<? super E> predicate)
Returns a predicated (validating) bag backed by the given bag.
|
static <E> SortedBag<E> |
predicatedSortedBag(SortedBag<E> bag,
Predicate<? super E> predicate)
Returns a predicated (validating) sorted bag backed by the given sorted
bag.
|
static <E> Bag<E> |
synchronizedBag(Bag<E> bag)
Returns a synchronized (thread-safe) bag backed by the given bag.
|
static <E> SortedBag<E> |
synchronizedSortedBag(SortedBag<E> bag)
Returns a synchronized (thread-safe) sorted bag backed by the given
sorted bag.
|
static <E> Bag<E> |
transformingBag(Bag<E> bag,
Transformer<? super E,? extends E> transformer)
Returns a transformed bag backed by the given bag.
|
static <E> SortedBag<E> |
transformingSortedBag(SortedBag<E> bag,
Transformer<? super E,? extends E> transformer)
Returns a transformed sorted bag backed by the given bag.
|
static <E> Bag<E> |
unmodifiableBag(Bag<? extends E> bag)
Returns an unmodifiable view of the given bag.
|
static <E> SortedBag<E> |
unmodifiableSortedBag(SortedBag<E> bag)
Returns an unmodifiable view of the given sorted bag.
|
public static final Bag EMPTY_SORTED_BAG
public static <E> Bag<E> synchronizedBag(Bag<E> 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.
E
- the element typebag
- the bag to synchronize, must not be nullNullPointerException
- if the Bag is nullpublic static <E> Bag<E> unmodifiableBag(Bag<? extends E> bag)
UnsupportedOperationException
.E
- the element typebag
- the bag whose unmodifiable view is to be returned, must not be nullNullPointerException
- if the Bag is nullpublic static <E> Bag<E> predicatedBag(Bag<E> bag, Predicate<? super E> 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.
E
- the element typebag
- the bag to predicate, must not be nullpredicate
- the predicate for the bag, must not be nullNullPointerException
- if the Bag or Predicate is nullpublic static <E> Bag<E> transformingBag(Bag<E> bag, Transformer<? super E,? extends E> 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.
Existing entries in the specified bag will not be transformed.
If you want that behaviour, see TransformedBag.transformedBag(Bag, Transformer)
.
E
- the element typebag
- the bag to predicate, must not be nulltransformer
- the transformer for the bag, must not be nullNullPointerException
- if the Bag or Transformer is nullpublic static <E> Bag<E> collectionBag(Bag<E> bag)
E
- the element typebag
- the bag to decorate, must not be nullNullPointerException
- if bag is nullpublic static <E> SortedBag<E> synchronizedSortedBag(SortedBag<E> 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.
E
- the element typebag
- the bag to synchronize, must not be nullNullPointerException
- if the SortedBag is nullpublic static <E> SortedBag<E> unmodifiableSortedBag(SortedBag<E> bag)
UnsupportedOperationException
.E
- the element typebag
- the bag whose unmodifiable view is to be returned, must not be nullNullPointerException
- if the SortedBag is nullpublic static <E> SortedBag<E> predicatedSortedBag(SortedBag<E> bag, Predicate<? super E> 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.
E
- the element typebag
- the sorted bag to predicate, must not be nullpredicate
- the predicate for the bag, must not be nullNullPointerException
- if the SortedBag or Predicate is nullpublic static <E> SortedBag<E> transformingSortedBag(SortedBag<E> bag, Transformer<? super E,? extends E> 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.
Existing entries in the specified bag will not be transformed.
If you want that behaviour, see
TransformedSortedBag.transformedSortedBag(SortedBag, Transformer)
.
E
- the element typebag
- the bag to predicate, must not be nulltransformer
- the transformer for the bag, must not be nullNullPointerException
- if the Bag or Transformer is nullpublic static <E> Bag<E> emptyBag()
Bag
.E
- the element typepublic static <E> SortedBag<E> emptySortedBag()
SortedBag
.E
- the element typeCopyright © 2001–2018 The Apache Software Foundation. All rights reserved.