Top Description Fields Constructors Methods
org.apache.commons.collections4.bag

public Class PredicatedSortedBag<E>

extends PredicatedBag<E>
implements SortedBag<E>
Class Inheritance
All Implemented Interfaces
org.apache.commons.collections4.SortedBag, org.apache.commons.collections4.Bag, java.util.Collection, java.lang.Iterable
Type Parameters
<E>
the type of elements in this bag
Imports
java.util.Comparator, org.apache.commons.collections4.Predicate, .SortedBag

Decorates another 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.

Since
3.0

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
protected
PredicatedSortedBag(final SortedBag<E>
the bag to decorate, must not be null
bag
,
final Predicate<? super E>
the predicate to use for validation, must not be null
predicate
)

Constructor that wraps (not copies).

Method Summary

Modifier and TypeMethod and Description
public Comparator<? super E>
comparator()

Implements org.apache.commons.collections4.SortedBag.comparator.

Returns the comparator associated with this sorted set, or null if it uses its elements' natural ordering.
protected SortedBag<E>

Returns:

the decorated bag
decorated
()

Overrides org.apache.commons.collections4.bag.PredicatedBag.decorated.

Gets the decorated sorted bag.
public E
first()

Implements org.apache.commons.collections4.SortedBag.first.

Returns the first (lowest) member.
public E
last()

Implements org.apache.commons.collections4.SortedBag.last.

Returns the last (highest) member.
public static <
the type of the elements in the bag
E
>
PredicatedSortedBag<E>

Returns:

a new predicated SortedBag
predicatedSortedBag
(final SortedBag<E>
the bag to decorate, must not be null
bag
,
final Predicate<? super E>
the predicate to use for validation, must not be null
predicate
)

Factory method to create a predicated (validating) bag.

Inherited from org.apache.commons.collections4.bag.PredicatedBag:
addequalsgetCounthashCodepredicatedBagremoveuniqueSet

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.collections4.bag.PredicatedBag.serialVersionUID.

Serialization version

Constructor Detail

PredicatedSortedBagback to summary
protected PredicatedSortedBag(final SortedBag<E> bag, final Predicate<? super E> predicate)

Constructor that wraps (not copies).

If there are any elements already in the bag being decorated, they are validated.

Parameters
bag:SortedBag<E>

the bag to decorate, must not be null

predicate:Predicate<? super E>

the predicate to use for validation, must not be null

Exceptions
NullPointerException:
if bag or predicate is null
IllegalArgumentException:
if the bag contains invalid elements

Method Detail

comparatorback to summary
public Comparator<? super E> comparator()

Implements org.apache.commons.collections4.SortedBag.comparator.

Doc from org.apache.commons.collections4.SortedBag.comparator.

Returns the comparator associated with this sorted set, or null if it uses its elements' natural ordering.

Returns:Comparator<? super E>

the comparator in use, or null if natural ordering

Annotations
@Override
decoratedback to summary
protected SortedBag<E> decorated()

Overrides org.apache.commons.collections4.bag.PredicatedBag.decorated.

Gets the decorated sorted bag.

Returns:SortedBag<E>

the decorated bag

Annotations
@Override
firstback to summary
public E first()

Implements org.apache.commons.collections4.SortedBag.first.

Doc from org.apache.commons.collections4.SortedBag.first.

Returns the first (lowest) member.

Returns:E

the first element in the sorted bag

Annotations
@Override
lastback to summary
public E last()

Implements org.apache.commons.collections4.SortedBag.last.

Doc from org.apache.commons.collections4.SortedBag.last.

Returns the last (highest) member.

Returns:E

the last element in the sorted bag

Annotations
@Override
predicatedSortedBagback to summary
public static <E> PredicatedSortedBag<E> predicatedSortedBag(final SortedBag<E> bag, final Predicate<? super E> predicate)

Factory method to create a predicated (validating) bag.

If there are any elements already in the bag being decorated, they are validated.

Parameters
<E>
the type of the elements in the bag
bag:SortedBag<E>

the bag to decorate, must not be null

predicate:Predicate<? super E>

the predicate to use for validation, must not be null

Returns:PredicatedSortedBag<E>

a new predicated SortedBag

Exceptions
NullPointerException:
if bag or predicate is null
IllegalArgumentException:
if the bag contains invalid elements
Since
4.0