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.
Modifier and Type | Method and Description |
---|---|
java.util.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.
|
java.lang.Object |
first()
Returns the first (lowest) member.
|
java.lang.Object |
last()
Returns the last (highest) member.
|
add, decorate, getCount, remove, uniqueSet
add, addAll, decorate
clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString
add, add, containsAll, getCount, iterator, remove, remove, removeAll, retainAll, size, uniqueSet
public 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 nulljava.lang.IllegalArgumentException
- if bag or predicate is nulljava.lang.IllegalArgumentException
- if the bag contains invalid elementspublic java.lang.Object first()
SortedBag
public java.lang.Object last()
SortedBag
public java.util.Comparator comparator()
SortedBag
comparator
in interface SortedBag
Copyright © 2010 - 2020 Adobe. All Rights Reserved