public class PredicatedSortedBag<E> extends PredicatedBag<E> implements SortedBag<E>
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.predicatedSortedBag(new TreeBag(), NotNullPredicate.INSTANCE);
This class is Serializable from Commons Collections 3.1.
PredicatedCollection.Builder<E>
predicate
Modifier | Constructor | Description |
---|---|---|
protected |
PredicatedSortedBag(SortedBag<E> bag,
Predicate<? super E> predicate) |
Constructor that wraps (not copies).
|
Modifier and Type | Method | Description |
---|---|---|
java.util.Comparator<? super E> |
comparator() |
Returns the comparator associated with this sorted set, or null
if it uses its elements' natural ordering.
|
protected SortedBag<E> |
decorated() |
Gets the decorated sorted bag.
|
E |
first() |
Returns the first (lowest) member.
|
E |
last() |
Returns the last (highest) member.
|
static <E> PredicatedSortedBag<E> |
predicatedSortedBag(SortedBag<E> bag,
Predicate<? super E> predicate) |
Factory method to create a predicated (validating) bag.
|
clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, setCollection, size, toArray, toArray, toString
add, add, containsAll, getCount, iterator, remove, remove, removeAll, retainAll, size, uniqueSet
addAll, clear, contains, equals, hashCode, isEmpty, parallelStream, removeIf, spliterator, stream, toArray, toArray
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
add, equals, getCount, hashCode, predicatedBag, remove, uniqueSet
add, addAll, builder, notNullBuilder, predicatedCollection, validate
protected PredicatedSortedBag(SortedBag<E> bag, Predicate<? super E> 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.NullPointerException
- if bag or predicate is nulljava.lang.IllegalArgumentException
- if the bag contains invalid elementspublic static <E> PredicatedSortedBag<E> predicatedSortedBag(SortedBag<E> bag, Predicate<? super E> predicate)
If there are any elements already in the bag being decorated, they are validated.
E
- the type of the elements in the bagbag
- the bag to decorate, must not be nullpredicate
- the predicate to use for validation, must not be nulljava.lang.NullPointerException
- if bag or predicate is nulljava.lang.IllegalArgumentException
- if the bag contains invalid elementsprotected SortedBag<E> decorated()
decorated
in class PredicatedBag<E>
public E first()
SortedBag
public E last()
SortedBag
public java.util.Comparator<? super E> comparator()
SortedBag
comparator
in interface SortedBag<E>
Copyright © 2001-2019 - Apache Software Foundation