public class PredicatedSortedBag extends PredicatedBag implements SortedBag
SortedBag
to validate that additions
match a specified predicate.
This bag exists to provide validation for the decorated bag. It is normally created to decorate an empty bag. If an object cannot be added to the bag, an IllegalArgumentException is thrown.
One usage would be to ensure that no null entries are added to the bag.
SortedBag bag = PredicatedSortedBag.decorate(new TreeBag(), NotNullPredicate.INSTANCE);
This class is Serializable from Commons Collections 3.1.
predicate
collection
Modifier | Constructor and Description |
---|---|
protected |
PredicatedSortedBag(SortedBag bag,
Predicate predicate)
Constructor that wraps (not copies).
|
Modifier and Type | Method and Description |
---|---|
Comparator |
comparator()
Returns the comparator associated with this sorted set, or null
if it uses its elements' natural ordering.
|
static SortedBag |
decorate(SortedBag bag,
Predicate predicate)
Factory method to create a predicated (validating) bag.
|
Object |
first()
Returns the first (lowest) member.
|
protected SortedBag |
getSortedBag()
Gets the decorated sorted bag.
|
Object |
last()
Returns the last (highest) member.
|
add, decorate, getBag, getCount, remove, uniqueSet
add, addAll, decorate, validate
clear, contains, containsAll, equals, getCollection, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
protected PredicatedSortedBag(SortedBag bag, Predicate predicate)
If there are any elements already in the bag being decorated, they are validated.
bag
- the bag to decorate, must not be nullpredicate
- the predicate to use for validation, must not be nullIllegalArgumentException
- if bag or predicate is nullIllegalArgumentException
- if the bag contains invalid elementspublic static SortedBag decorate(SortedBag bag, Predicate predicate)
If there are any elements already in the bag being decorated, they are validated.
bag
- the bag to decorate, must not be nullpredicate
- the predicate to use for validation, must not be nullIllegalArgumentException
- if bag or predicate is nullIllegalArgumentException
- if the bag contains invalid elementsprotected SortedBag getSortedBag()
public Object first()
SortedBag
public Object last()
SortedBag
public Comparator comparator()
SortedBag
comparator
in interface SortedBag
Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.