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

public Class PredicatedSortedSet<E>

extends PredicatedSet<E>
implements SortedSet<E>
Class Inheritance
All Implemented Interfaces
java.util.SortedSet, java.util.SequencedSet, java.util.Set, java.util.Collection, java.lang.Iterable, java.util.SequencedCollection
Known Direct Subclasses
org.apache.commons.collections4.set.PredicatedNavigableSet
Type Parameters
<E>
the type of the elements in this set
Imports
java.util.Comparator, .SortedSet, org.apache.commons.collections4.Predicate

Decorates another SortedSet to validate that all additions match a specified predicate.

This set exists to provide validation for the decorated set. It is normally created to decorate an empty set. If an object cannot be added to the set, an IllegalArgumentException is thrown.

One usage would be to ensure that no null entries are added to the set.

SortedSet set =
  PredicatedSortedSet.predicatedSortedSet(new TreeSet(),
                                          NotNullPredicate.notNullPredicate());

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
PredicatedSortedSet(final SortedSet<E>
the set to decorate, must not be null
set
,
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 java.util.SortedSet.comparator.

Returns the comparator used to order the elements in this set, or null if this set uses the natural ordering of its elements.
protected SortedSet<E>

Returns:

the decorated sorted set
decorated
()

Overrides org.apache.commons.collections4.set.PredicatedSet.decorated.

Gets the sorted set being decorated.
public E
first()

Implements java.util.SortedSet.first.

Returns the first (lowest) element currently in this set.
public SortedSet<E>
headSet(final E
high endpoint (exclusive) of the returned set
toElement
)

Implements java.util.SortedSet.headSet.

Returns a view of the portion of this set whose elements are strictly less than toElement.
public E
last()

Implements java.util.SortedSet.last.

Returns the last (highest) element currently in this set.
public static <
the element type
E
>
PredicatedSortedSet<E>

Returns:

a new predicated sorted set.
predicatedSortedSet
(final SortedSet<E>
the set to decorate, must not be null
set
,
final Predicate<? super E>
the predicate to use for validation, must not be null
predicate
)

Factory method to create a predicated (validating) sorted set.

public SortedSet<E>
subSet(final E
low endpoint (inclusive) of the returned set
fromElement
,
final E
high endpoint (exclusive) of the returned set
toElement
)

Implements java.util.SortedSet.subSet.

Returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive.
public SortedSet<E>
tailSet(final E
low endpoint (inclusive) of the returned set
fromElement
)

Implements java.util.SortedSet.tailSet.

Returns a view of the portion of this set whose elements are greater than or equal to fromElement.
Inherited from org.apache.commons.collections4.set.PredicatedSet:
equalshashCodepredicatedSet

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.collections4.set.PredicatedSet.serialVersionUID.

Serialization version

Constructor Detail

PredicatedSortedSetback to summary
protected PredicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate)

Constructor that wraps (not copies).

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

Parameters
set:SortedSet<E>

the set to decorate, must not be null

predicate:Predicate<? super E>

the predicate to use for validation, must not be null

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

Method Detail

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

Implements java.util.SortedSet.comparator.

Doc from java.util.SortedSet.comparator.

Returns the comparator used to order the elements in this set, or null if this set uses the natural ordering of its elements.

Returns:Comparator<? super E>

the comparator used to order the elements in this set, or null if this set uses the natural ordering of its elements

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

Overrides org.apache.commons.collections4.set.PredicatedSet.decorated.

Gets the sorted set being decorated.

Returns:SortedSet<E>

the decorated sorted set

Annotations
@Override
firstback to summary
public E first()

Implements java.util.SortedSet.first.

Doc from java.util.SortedSet.first.

Returns the first (lowest) element currently in this set.

Returns:E

the first (lowest) element currently in this set

Annotations
@Override
headSetback to summary
public SortedSet<E> headSet(final E toElement)

Implements java.util.SortedSet.headSet.

Doc from java.util.SortedSet.headSet.

Returns a view of the portion of this set whose elements are strictly less than toElement. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.

The returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.

Parameters
toElement:E

high endpoint (exclusive) of the returned set

Returns:SortedSet<E>

a view of the portion of this set whose elements are strictly less than toElement

Annotations
@Override
lastback to summary
public E last()

Implements java.util.SortedSet.last.

Doc from java.util.SortedSet.last.

Returns the last (highest) element currently in this set.

Returns:E

the last (highest) element currently in this set

Annotations
@Override
predicatedSortedSetback to summary
public static <E> PredicatedSortedSet<E> predicatedSortedSet(final SortedSet<E> set, final Predicate<? super E> predicate)

Factory method to create a predicated (validating) sorted set.

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

Parameters
<E>
the element type
set:SortedSet<E>

the set to decorate, must not be null

predicate:Predicate<? super E>

the predicate to use for validation, must not be null

Returns:PredicatedSortedSet<E>

a new predicated sorted set.

Exceptions
NullPointerException:
if set or predicate is null
IllegalArgumentException:
if the set contains invalid elements
Since
4.0
subSetback to summary
public SortedSet<E> subSet(final E fromElement, final E toElement)

Implements java.util.SortedSet.subSet.

Doc from java.util.SortedSet.subSet.

Returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive. (If fromElement and toElement are equal, the returned set is empty.) The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.

The returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.

Parameters
fromElement:E

low endpoint (inclusive) of the returned set

toElement:E

high endpoint (exclusive) of the returned set

Returns:SortedSet<E>

a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive

Annotations
@Override
tailSetback to summary
public SortedSet<E> tailSet(final E fromElement)

Implements java.util.SortedSet.tailSet.

Doc from java.util.SortedSet.tailSet.

Returns a view of the portion of this set whose elements are greater than or equal to fromElement. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.

The returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.

Parameters
fromElement:E

low endpoint (inclusive) of the returned set

Returns:SortedSet<E>

a view of the portion of this set whose elements are greater than or equal to fromElement

Annotations
@Override