Class AbstractNavigableSet<E>
- Type Parameters:
E
- element type
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,NavigableSet<E>
,Set<E>
,SortedSet<E>
- Direct Known Subclasses:
AbstractKVNavigableSet
,ConvertedNavigableSet
,ImmutableNavigableSet
NavigableSet
implementations based on database entries.
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.
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
Convenience constructor for the case where there are no lower or upper bounds.protected
AbstractNavigableSet
(Bounds<E> bounds) Primary constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected Spliterator<E>
buildSpliterator
(Iterator<E> iterator) Build aSpliterator
appropriate for this set from the given instance iterator.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.first()
Get theBounds
associated with this instance.protected Comparator<? super E>
getComparator
(boolean reversed) Get a non-nullComparator
that sorts consistently with, and optionally reversed from, this instance.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).last()
pollLast()
boolean
Removes the given element from this set if it is present.protected E
searchAbove
(E elem, boolean inclusive) Search for a higher element.protected E
searchBelow
(E elem, boolean inclusive) Search for a lower element.Methods inherited from class io.permazen.util.AbstractIterationSet
equals, hashCode, isEmpty, iterator, size, spliterator, stream, toArray, toArray
Methods inherited from class java.util.AbstractSet
removeAll
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, retainAll, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.NavigableSet
iterator
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, size, toArray, toArray
Methods inherited from interface java.util.SortedSet
comparator, spliterator
-
Field Details
-
bounds
Element range bounds associated with this instance.
-
-
Constructor Details
-
AbstractNavigableSet
protected AbstractNavigableSet()Convenience constructor for the case where there are no lower or upper bounds. -
AbstractNavigableSet
Primary constructor.- Parameters:
bounds
- range restriction- Throws:
IllegalArgumentException
- ifbounds
is null
-
-
Method Details
-
getBounds
Get theBounds
associated with this instance.- Returns:
- range restriction
-
remove
Removes the given element from this set if it is present.The implementation in
AbstractNavigableSet
always throwsUnsupportedOperationException
.- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceSet<E>
- Overrides:
remove
in classAbstractCollection<E>
-
first
-
last
-
pollFirst
- Specified by:
pollFirst
in interfaceNavigableSet<E>
-
pollLast
- Specified by:
pollLast
in interfaceNavigableSet<E>
-
descendingIterator
- Specified by:
descendingIterator
in interfaceNavigableSet<E>
-
lower
- Specified by:
lower
in interfaceNavigableSet<E>
-
floor
- Specified by:
floor
in interfaceNavigableSet<E>
-
ceiling
- Specified by:
ceiling
in interfaceNavigableSet<E>
-
higher
- Specified by:
higher
in interfaceNavigableSet<E>
-
headSet
-
tailSet
-
subSet
-
descendingSet
- Specified by:
descendingSet
in interfaceNavigableSet<E>
-
headSet
- Specified by:
headSet
in interfaceNavigableSet<E>
-
tailSet
- Specified by:
tailSet
in interfaceNavigableSet<E>
-
subSet
public NavigableSet<E> subSet(E newMinElement, boolean minInclusive, E newMaxElement, boolean maxInclusive) - Specified by:
subSet
in interfaceNavigableSet<E>
-
buildSpliterator
Description copied from class:AbstractIterationSet
Build aSpliterator
appropriate for this set from the given instance iterator.Implementations should probably use
Spliterators.spliteratorUnknownSize()
unless the size is known.- Overrides:
buildSpliterator
in classAbstractIterationSet<E>
- Parameters:
iterator
- a new iterator returned from {#link #iterator}
-
searchBelow
Search for a lower element. Used to implementfloor()
andlower()
.The implementation in
AbstractNavigableSet
checks the bounds then returns the first element from a head set.- Parameters:
elem
- upper limit for searchinclusive
- true ifelem
itself is a candidate- Returns:
- highest element below
elem
, or null if not found
-
searchAbove
Search for a higher element. Used to implementceiling()
andhigher()
.The implementation in
AbstractNavigableSet
checks the bounds then returns the first element from a tail set.- Parameters:
elem
- lower limit for searchinclusive
- true ifelem
itself is a candidate- Returns:
- lowest element above
elem
, or null if not found
-
getComparator
Get a non-nullComparator
that sorts consistently with, and optionally reversed from, this instance.- Parameters:
reversed
- whether to return a reversedComparator
- Returns:
- a non-null
Comparator
-
createSubSet
Create a (possibly reversed) view of this instance with (possibly) tighter lower and/or upper bounds. ThenewBounds
are consistent with the new ordering (i.e., reversed relative to this instance's ordering ifreverse
is true) and have already been range-checked against this instance's current bounds.- Parameters:
reverse
- whether the new set's ordering should be reversed relative to this instance's orderingnewBounds
- new bounds- Returns:
- restricted and/or reversed view of this instance
- Throws:
IllegalArgumentException
- ifnewBounds
is nullIllegalArgumentException
- if a bound innewBounds
is null and this set does not permit null elements
-
isWithinLowerBound
Determine if the given element is within this instance's lower bound (if any).The implementation in
AbstractNavigableSet
returnsthis.bounds.isWithinLowerBound(this.comparator(), elem)
.- Parameters:
elem
- set element- Returns:
- true if
elem
is within this instance's lower bound, or this instance has no lower bound
-
isWithinUpperBound
Determine if the given element is within this instance's upper bound (if any).The implementation in
AbstractNavigableSet
returnsthis.bounds.isWithinUpperBound(this.comparator(), elem)
.- Parameters:
elem
- set element- Returns:
- true if
elem
is within this instance's upper bound, or this instance has no upper bound
-