@GwtIncompatible public abstract class ForwardingNavigableSet<E> extends ForwardingSortedSet<E> implements NavigableSet<E>
Warning: The methods of ForwardingNavigableSet
forward indiscriminately
to the methods of the delegate. For example, overriding ForwardingCollection.add(E)
alone will not
change the behavior of ForwardingCollection.addAll(java.util.Collection<? extends E>)
, which can lead to unexpected behavior. In this case, you
should override addAll
as well, either providing your own implementation, or delegating
to the provided standardAddAll
method.
default
method warning: This class does not forward calls to default
methods. Instead, it inherits their default implementations. When those implementations
invoke methods, they invoke methods on the ForwardingNavigableSet
.
Each of the standard
methods uses the set's comparator (or the natural ordering of
the elements, if there is no comparator) to test element equality. As a result, if the
comparator is not consistent with equals, some of the standard implementations may violate the
Set
contract.
The standard
methods and the collection views they return are not guaranteed to be
thread-safe, even when all of the methods that they depend on are thread-safe.
Modifier and Type | Class and Description |
---|---|
protected class |
ForwardingNavigableSet.StandardDescendingSet
A sensible implementation of
NavigableSet.descendingSet() in terms of the other methods
of NavigableSet , notably including NavigableSet.descendingIterator() . |
Modifier | Constructor and Description |
---|---|
protected |
ForwardingNavigableSet()
Constructor for use by subclasses.
|
Modifier and Type | Method and Description |
---|---|
E |
ceiling(E e)
Returns the least element in this set greater than or equal to
the given element, or
null if there is no such element. |
protected abstract NavigableSet<E> |
delegate()
Returns the backing delegate instance that methods are forwarded to.
|
Iterator<E> |
descendingIterator()
Returns an iterator over the elements in this set, in descending order.
|
NavigableSet<E> |
descendingSet()
Returns a reverse order view of the elements contained in this set.
|
E |
floor(E e)
Returns the greatest element in this set less than or equal to
the given element, or
null if there is no such element. |
NavigableSet<E> |
headSet(E toElement,
boolean inclusive)
Returns a view of the portion of this set whose elements are less than
(or equal to, if
inclusive is true) toElement . |
E |
higher(E e)
Returns the least element in this set strictly greater than the
given element, or
null if there is no such element. |
E |
lower(E e)
Returns the greatest element in this set strictly less than the
given element, or
null if there is no such element. |
E |
pollFirst()
Retrieves and removes the first (lowest) element,
or returns
null if this set is empty. |
E |
pollLast()
Retrieves and removes the last (highest) element,
or returns
null if this set is empty. |
protected E |
standardCeiling(E e)
|
protected E |
standardFirst() |
protected E |
standardFloor(E e)
A sensible definition of
floor(E) in terms of the descendingIterator method of
headSet(Object, boolean) . |
protected SortedSet<E> |
standardHeadSet(E toElement)
A sensible definition of
ForwardingSortedSet.headSet(Object) in terms of the
headSet(Object, boolean) method. |
protected E |
standardHigher(E e)
|
protected E |
standardLast() |
protected E |
standardLower(E e)
A sensible definition of
lower(E) in terms of the descendingIterator method of
headSet(Object, boolean) . |
protected E |
standardPollFirst()
A sensible definition of
pollFirst() in terms of the iterator method. |
protected E |
standardPollLast()
A sensible definition of
pollLast() in terms of the descendingIterator method. |
protected NavigableSet<E> |
standardSubSet(E fromElement,
boolean fromInclusive,
E toElement,
boolean toInclusive)
A sensible definition of
subSet(Object, boolean, Object, boolean) in terms of the
headSet and tailSet methods. |
protected SortedSet<E> |
standardSubSet(E fromElement,
E toElement)
A sensible definition of
ForwardingSortedSet.subSet(Object, Object) in terms of the
subSet(Object, boolean, Object, boolean) method. |
protected SortedSet<E> |
standardTailSet(E fromElement)
A sensible definition of
ForwardingSortedSet.tailSet(Object) in terms of the
tailSet(Object, boolean) method. |
NavigableSet<E> |
subSet(E fromElement,
boolean fromInclusive,
E toElement,
boolean toInclusive)
Returns a view of the portion of this set whose elements range from
fromElement to toElement . |
NavigableSet<E> |
tailSet(E fromElement,
boolean inclusive)
Returns a view of the portion of this set whose elements are greater
than (or equal to, if
inclusive is true) fromElement . |
comparator, first, headSet, last, standardContains, standardRemove, subSet, tailSet
equals, hashCode, standardEquals, standardHashCode, standardRemoveAll
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, standardAddAll, standardClear, standardContainsAll, standardIsEmpty, standardRetainAll, standardToArray, standardToArray, standardToString, toArray, toArray
toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
headSet, iterator, subSet, tailSet
comparator, first, last, spliterator
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, size, toArray, toArray
parallelStream, removeIf, stream
protected ForwardingNavigableSet()
protected abstract NavigableSet<E> delegate()
ForwardingObject
ForwardingSet.delegate()
. Concrete subclasses override this method to supply
the instance being decorated.delegate
in class ForwardingSortedSet<E>
public E lower(E e)
java.util.NavigableSet
null
if there is no such element.lower
in interface NavigableSet<E>
e
- the value to matche
,
or null
if there is no such elementprotected E standardLower(E e)
lower(E)
in terms of the descendingIterator
method of
headSet(Object, boolean)
. If you override headSet(Object, boolean)
, you may
wish to override lower(E)
to forward to this implementation.public E floor(E e)
java.util.NavigableSet
null
if there is no such element.floor
in interface NavigableSet<E>
e
- the value to matche
,
or null
if there is no such elementprotected E standardFloor(E e)
floor(E)
in terms of the descendingIterator
method of
headSet(Object, boolean)
. If you override headSet(Object, boolean)
, you may
wish to override floor(E)
to forward to this implementation.public E ceiling(E e)
java.util.NavigableSet
null
if there is no such element.ceiling
in interface NavigableSet<E>
e
- the value to matche
,
or null
if there is no such elementprotected E standardCeiling(E e)
ceiling(E)
in terms of the iterator
method of
tailSet(Object, boolean)
. If you override tailSet(Object, boolean)
, you may
wish to override ceiling(E)
to forward to this implementation.public E higher(E e)
java.util.NavigableSet
null
if there is no such element.higher
in interface NavigableSet<E>
e
- the value to matche
,
or null
if there is no such elementprotected E standardHigher(E e)
higher(E)
in terms of the iterator
method of
tailSet(Object, boolean)
. If you override tailSet(Object, boolean)
, you may
wish to override higher(E)
to forward to this implementation.public E pollFirst()
java.util.NavigableSet
null
if this set is empty.pollFirst
in interface NavigableSet<E>
null
if this set is emptyprotected E standardPollFirst()
pollFirst()
in terms of the iterator
method. If you
override ForwardingCollection.iterator()
you may wish to override pollFirst()
to forward to this
implementation.public E pollLast()
java.util.NavigableSet
null
if this set is empty.pollLast
in interface NavigableSet<E>
null
if this set is emptyprotected E standardPollLast()
pollLast()
in terms of the descendingIterator
method.
If you override descendingIterator()
you may wish to override pollLast()
to
forward to this implementation.protected E standardFirst()
protected E standardLast()
public NavigableSet<E> descendingSet()
java.util.NavigableSet
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
.
descendingSet
in interface NavigableSet<E>
public Iterator<E> descendingIterator()
java.util.NavigableSet
descendingSet().iterator()
.descendingIterator
in interface NavigableSet<E>
public NavigableSet<E> subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)
java.util.NavigableSet
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.
subSet
in interface NavigableSet<E>
fromElement
- low endpoint of the returned setfromInclusive
- true
if the low endpoint
is to be included in the returned viewtoElement
- high endpoint of the returned settoInclusive
- true
if the high endpoint
is to be included in the returned viewfromElement
, inclusive, to toElement
, exclusive@Beta protected NavigableSet<E> standardSubSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)
subSet(Object, boolean, Object, boolean)
in terms of the
headSet
and tailSet
methods. In many cases, you may wish to override
subSet(Object, boolean, Object, boolean)
to forward to this implementation.protected SortedSet<E> standardSubSet(E fromElement, E toElement)
ForwardingSortedSet.subSet(Object, Object)
in terms of the
subSet(Object, boolean, Object, boolean)
method. If you override
subSet(Object, boolean, Object, boolean)
, you may wish to override
ForwardingSortedSet.subSet(Object, Object)
to forward to this implementation.standardSubSet
in class ForwardingSortedSet<E>
public NavigableSet<E> headSet(E toElement, boolean inclusive)
java.util.NavigableSet
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.
headSet
in interface NavigableSet<E>
toElement
- high endpoint of the returned setinclusive
- true
if the high endpoint
is to be included in the returned viewinclusive
is true) toElement
protected SortedSet<E> standardHeadSet(E toElement)
ForwardingSortedSet.headSet(Object)
in terms of the
headSet(Object, boolean)
method. If you override
headSet(Object, boolean)
, you may wish to override
ForwardingSortedSet.headSet(Object)
to forward to this implementation.public NavigableSet<E> tailSet(E fromElement, boolean inclusive)
java.util.NavigableSet
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.
tailSet
in interface NavigableSet<E>
fromElement
- low endpoint of the returned setinclusive
- true
if the low endpoint
is to be included in the returned viewfromElement
protected SortedSet<E> standardTailSet(E fromElement)
ForwardingSortedSet.tailSet(Object)
in terms of the
tailSet(Object, boolean)
method. If you override
tailSet(Object, boolean)
, you may wish to override
ForwardingSortedSet.tailSet(Object)
to forward to this implementation.Copyright © 2010–2017. All rights reserved.