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

public Class PredicatedNavigableSet<E>

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

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

NavigableSet set =
  PredicatedSortedSet.predicatedNavigableSet(new TreeSet(),
                                             NotNullPredicate.notNullPredicate());
Since
4.1

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
protected
PredicatedNavigableSet(final NavigableSet<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 E
ceiling(final E
the value to match
e
)

Implements java.util.NavigableSet.ceiling.

Returns the least element in this set greater than or equal to the given element, or null if there is no such element.
protected NavigableSet<E>

Returns:

the decorated navigable set
decorated
()

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

Gets the navigable set being decorated.
public Iterator<E>
descendingIterator()

Implements java.util.NavigableSet.descendingIterator.

Returns an iterator over the elements in this set, in descending order.
public NavigableSet<E>
descendingSet()

Implements java.util.NavigableSet.descendingSet.

Returns a reverse order view of the elements contained in this set.
public E
floor(final E
the value to match
e
)

Implements java.util.NavigableSet.floor.

Returns the greatest element in this set less than or equal to the given element, or null if there is no such element.
public NavigableSet<E>
headSet(final E
high endpoint of the returned set
toElement
,
final boolean
true if the high endpoint is to be included in the returned view
inclusive
)

Implements java.util.NavigableSet.headSet.

Returns a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement.
public E
higher(final E
the value to match
e
)

Implements java.util.NavigableSet.higher.

Returns the least element in this set strictly greater than the given element, or null if there is no such element.
public E
lower(final E
the value to match
e
)

Implements java.util.NavigableSet.lower.

Returns the greatest element in this set strictly less than the given element, or null if there is no such element.
public E
pollFirst()

Implements java.util.NavigableSet.pollFirst.

Retrieves and removes the first (lowest) element, or returns null if this set is empty.
public E
pollLast()

Implements java.util.NavigableSet.pollLast.

Retrieves and removes the last (highest) element, or returns null if this set is empty.
public static <
the element type
E
>
PredicatedNavigableSet<E>

Returns:

a new predicated navigable set.
predicatedNavigableSet
(final NavigableSet<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) navigable set.

public NavigableSet<E>
subSet(final E
low endpoint of the returned set
fromElement
,
final boolean
true if the low endpoint is to be included in the returned view
fromInclusive
,
final E
high endpoint of the returned set
toElement
,
final boolean
true if the high endpoint is to be included in the returned view
toInclusive
)

Implements java.util.NavigableSet.subSet.

Returns a view of the portion of this set whose elements range from fromElement to toElement.
public NavigableSet<E>
tailSet(final E
low endpoint of the returned set
fromElement
,
final boolean
true if the low endpoint is to be included in the returned view
inclusive
)

Implements java.util.NavigableSet.tailSet.

Returns a view of the portion of this set whose elements are greater than (or equal to, if inclusive is true) fromElement.
Inherited from org.apache.commons.collections4.set.PredicatedSortedSet:
comparatorfirstheadSetlastpredicatedSortedSetsubSettailSet

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

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

Serialization version

Constructor Detail

PredicatedNavigableSetback to summary
protected PredicatedNavigableSet(final NavigableSet<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:NavigableSet<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

ceilingback to summary
public E ceiling(final E e)

Implements java.util.NavigableSet.ceiling.

Doc from java.util.NavigableSet.ceiling.

Returns the least element in this set greater than or equal to the given element, or null if there is no such element.

Parameters
e:E

the value to match

Returns:E

the least element greater than or equal to e, or null if there is no such element

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

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

Gets the navigable set being decorated.

Returns:NavigableSet<E>

the decorated navigable set

Annotations
@Override
descendingIteratorback to summary
public Iterator<E> descendingIterator()

Implements java.util.NavigableSet.descendingIterator.

Doc from java.util.NavigableSet.descendingIterator.

Returns an iterator over the elements in this set, in descending order. Equivalent in effect to descendingSet().iterator().

Returns:Iterator<E>

an iterator over the elements in this set, in descending order

Annotations
@Override
descendingSetback to summary
public NavigableSet<E> descendingSet()

Implements java.util.NavigableSet.descendingSet.

Doc from java.util.NavigableSet.descendingSet.

Returns a reverse order view of the elements contained in this set. The descending set is backed by this set, so changes to the set are reflected in the descending set, and vice-versa. If either set is modified while an iteration over either set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined.

The returned set has an ordering equivalent to Collections.reverseOrder(comparator()). The expression s.descendingSet().descendingSet() returns a view of s essentially equivalent to s.

Returns:NavigableSet<E>

a reverse order view of this set

Annotations
@Override
floorback to summary
public E floor(final E e)

Implements java.util.NavigableSet.floor.

Doc from java.util.NavigableSet.floor.

Returns the greatest element in this set less than or equal to the given element, or null if there is no such element.

Parameters
e:E

the value to match

Returns:E

the greatest element less than or equal to e, or null if there is no such element

Annotations
@Override
headSetback to summary
public NavigableSet<E> headSet(final E toElement, final boolean inclusive)

Implements java.util.NavigableSet.headSet.

Doc from java.util.NavigableSet.headSet.

Returns a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) 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 of the returned set

inclusive:boolean

true if the high endpoint is to be included in the returned view

Returns:NavigableSet<E>

a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement

Annotations
@Override
higherback to summary
public E higher(final E e)

Implements java.util.NavigableSet.higher.

Doc from java.util.NavigableSet.higher.

Returns the least element in this set strictly greater than the given element, or null if there is no such element.

Parameters
e:E

the value to match

Returns:E

the least element greater than e, or null if there is no such element

Annotations
@Override
lowerback to summary
public E lower(final E e)

Implements java.util.NavigableSet.lower.

Doc from java.util.NavigableSet.lower.

Returns the greatest element in this set strictly less than the given element, or null if there is no such element.

Parameters
e:E

the value to match

Returns:E

the greatest element less than e, or null if there is no such element

Annotations
@Override
pollFirstback to summary
public E pollFirst()

Implements java.util.NavigableSet.pollFirst.

Doc from java.util.NavigableSet.pollFirst.

Retrieves and removes the first (lowest) element, or returns null if this set is empty.

Returns:E

the first element, or null if this set is empty

Annotations
@Override
pollLastback to summary
public E pollLast()

Implements java.util.NavigableSet.pollLast.

Doc from java.util.NavigableSet.pollLast.

Retrieves and removes the last (highest) element, or returns null if this set is empty.

Returns:E

the last element, or null if this set is empty

Annotations
@Override
predicatedNavigableSetback to summary
public static <E> PredicatedNavigableSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate)

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

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

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

the set to decorate, must not be null

predicate:Predicate<? super E>

the predicate to use for validation, must not be null

Returns:PredicatedNavigableSet<E>

a new predicated navigable set.

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

Implements java.util.NavigableSet.subSet.

Doc from java.util.NavigableSet.subSet.

Returns a view of the portion of this set whose elements range from fromElement to toElement. If fromElement and toElement are equal, the returned set is empty unless fromInclusive and toInclusive are both true. 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 of the returned set

fromInclusive:boolean

true if the low endpoint is to be included in the returned view

toElement:E

high endpoint of the returned set

toInclusive:boolean

true if the high endpoint is to be included in the returned view

Returns:NavigableSet<E>

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

Annotations
@Override
tailSetback to summary
public NavigableSet<E> tailSet(final E fromElement, final boolean inclusive)

Implements java.util.NavigableSet.tailSet.

Doc from java.util.NavigableSet.tailSet.

Returns a view of the portion of this set whose elements are greater than (or equal to, if inclusive is true) 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 of the returned set

inclusive:boolean

true if the low endpoint is to be included in the returned view

Returns:NavigableSet<E>

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

Annotations
@Override