E - element typepublic abstract class AbstractNavigableSet<E> extends AbstractIterationSet<E> implements NavigableSet<E>
NavigableSet implementations for which calculating size() requires
an iteration through all of the set's elements to count them.
For a read-only implementation, subclasses should implement comparator(), contains(),
iterator(), and createSubSet() to handle reversed and restricted range sub-sets.
For a mutable implementation, subclasses should also implement add(), remove(),
clear(), and make the iterator() mutable.
All overridden methods must be aware of the range restriction bounds, if any.
| Modifier and Type | Field and Description |
|---|---|
protected Bounds<E> |
bounds
Element range bounds associated with this instance.
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractNavigableSet()
Convenience constructor for the case where there are no lower or upper bounds.
|
protected |
AbstractNavigableSet(Bounds<E> bounds)
Primary constructor.
|
| Modifier and Type | Method and Description |
|---|---|
E |
ceiling(E elem) |
protected abstract NavigableSet<E> |
createSubSet(boolean reverse,
Bounds<E> newBounds)
Create a (possibly reversed) view of this instance with (possibly) tighter lower and/or upper bounds.
|
Iterator<E> |
descendingIterator() |
NavigableSet<E> |
descendingSet() |
E |
first() |
E |
floor(E elem) |
protected Comparator<? super E> |
getComparator(boolean reversed)
Get a non-null
Comparator that sorts consistently with, and optionally reversed from, this instance. |
NavigableSet<E> |
headSet(E newMaxElement) |
NavigableSet<E> |
headSet(E newMaxElement,
boolean inclusive) |
E |
higher(E elem) |
protected boolean |
isWithinLowerBound(E elem)
Determine if the given element is within this instance's lower bound (if any).
|
protected boolean |
isWithinUpperBound(E elem)
Determine if the given element is within this instance's upper bound (if any).
|
E |
last() |
E |
lower(E elem) |
E |
pollFirst() |
E |
pollLast() |
protected E |
searchAbove(E elem,
boolean inclusive)
Search for a higher element.
|
protected E |
searchBelow(E elem,
boolean inclusive)
Search for a lower element.
|
NavigableSet<E> |
subSet(E newMinElement,
boolean minInclusive,
E newMaxElement,
boolean maxInclusive) |
NavigableSet<E> |
subSet(E newMinElement,
E newMaxElement) |
NavigableSet<E> |
tailSet(E newMinElement) |
NavigableSet<E> |
tailSet(E newMinElement,
boolean inclusive) |
equals, hashCode, isEmpty, size, toArray, toArrayremoveAlladd, addAll, clear, contains, containsAll, iterator, remove, retainAll, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waititeratorcomparatorprotected AbstractNavigableSet()
protected AbstractNavigableSet(Bounds<E> bounds)
bounds - range restrictionIllegalArgumentException - if bounds is nullpublic E pollFirst()
pollFirst in interface NavigableSet<E>public E pollLast()
pollLast in interface NavigableSet<E>public Iterator<E> descendingIterator()
descendingIterator in interface NavigableSet<E>public E lower(E elem)
lower in interface NavigableSet<E>public E floor(E elem)
floor in interface NavigableSet<E>public E ceiling(E elem)
ceiling in interface NavigableSet<E>public E higher(E elem)
higher in interface NavigableSet<E>public NavigableSet<E> headSet(E newMaxElement)
public NavigableSet<E> tailSet(E newMinElement)
public NavigableSet<E> subSet(E newMinElement, E newMaxElement)
public NavigableSet<E> descendingSet()
descendingSet in interface NavigableSet<E>public NavigableSet<E> headSet(E newMaxElement, boolean inclusive)
headSet in interface NavigableSet<E>public NavigableSet<E> tailSet(E newMinElement, boolean inclusive)
tailSet in interface NavigableSet<E>public NavigableSet<E> subSet(E newMinElement, boolean minInclusive, E newMaxElement, boolean maxInclusive)
subSet in interface NavigableSet<E>protected E searchBelow(E elem, boolean inclusive)
floor() and lower().
The implementation in AbstractNavigableSet checks the bounds then returns the first element from a head set.
elem - upper limit for searchinclusive - true if elem itself is a candidateelem, or null if not foundprotected E searchAbove(E elem, boolean inclusive)
ceiling() and higher().
The implementation in AbstractNavigableSet checks the bounds then returns the first element from a tail set.
elem - lower limit for searchinclusive - true if elem itself is a candidateelem, or null if not foundprotected Comparator<? super E> getComparator(boolean reversed)
Comparator that sorts consistently with, and optionally reversed from, this instance.reversed - whether to return a reversed ComparatorComparatorprotected abstract NavigableSet<E> createSubSet(boolean reverse, Bounds<E> newBounds)
newBounds are consistent with the new ordering (i.e., reversed relative to this instance's ordering if
reverse is true) and have already been range-checked against this instance's current bounds.reverse - whether the new set's ordering should be reversed relative to this instance's orderingnewBounds - new boundsIllegalArgumentException - if newBounds is nullIllegalArgumentException - if a bound in newBounds is null and this set does not permit null elementsprotected boolean isWithinLowerBound(E elem)
The implementation in AbstractNavigableSet returns this.bounds.isWithinLowerBound(this.comparator(), elem).
elem - set elementelem is within this instance's lower bound, or this instance has no lower boundprotected boolean isWithinUpperBound(E elem)
The implementation in AbstractNavigableSet returns this.bounds.isWithinUpperBound(this.comparator(), elem).
elem - set elementelem is within this instance's upper bound, or this instance has no upper boundCopyright © 2016. All rights reserved.