Class AbstractNavigableMap<K,V>
- Type Parameters:
K
- key typeV
- value type
- All Implemented Interfaces:
Map<K,
,V> NavigableMap<K,
,V> SortedMap<K,
V>
- Direct Known Subclasses:
AbstractKVNavigableMap
,ConvertedNavigableMap
,ImmutableNavigableMap
NavigableMap
implementations based on database entries.
For a read-only implementation, subclasses should implement comparator()
, get()
,
entrySet()
, navigableKeySet()
, and createSubMap()
to handle reversed and restricted range sub-maps.
For a mutable implementation, subclasses should also implement put()
, remove()
,
clear()
, and make the navigableKeySet()
and entrySet()
iterators mutable.
All overridden methods must be aware of the range restriction bounds, if any.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
Convenience constructor for the case where there are no lower or upper key bounds.protected
AbstractNavigableMap
(Bounds<K> bounds) Primary constructor. -
Method Summary
Modifier and TypeMethodDescriptionceilingEntry
(K minKey) ceilingKey
(K minKey) boolean
containsKey
(Object obj) protected abstract NavigableMap<K,
V> createSubMap
(boolean reverse, Bounds<K> newBounds) Create a (possibly reversed) view of this instance with (possibly) tighter lower and/or upper bounds.firstKey()
floorEntry
(K maxKey) Get theBounds
associated with this instance.protected Comparator<? super K>
getComparator
(boolean reversed) Get a non-nullComparator
that sorts consistently with, and optionally reversed from, this instance.higherEntry
(K minKey) boolean
isEmpty()
protected boolean
isWithinLowerBound
(K key) Determine if the given element is within this instance's lower bound (if any).protected boolean
isWithinUpperBound
(K key) Determine if the given element is within this instance's upper bound (if any).keySet()
lastKey()
lowerEntry
(K maxKey) Removes the mapping for a key from this map if it is present.searchAbove
(K minKey, boolean inclusive) Search for a higher element.searchBelow
(K maxKey, boolean inclusive) Search for a lower element.Methods inherited from class java.util.AbstractMap
clear, clone, containsValue, entrySet, equals, get, hashCode, put, putAll, size, toString, values
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsValue, equals, forEach, get, getOrDefault, hashCode, merge, put, putAll, putIfAbsent, remove, replace, replace, replaceAll, size
Methods inherited from interface java.util.NavigableMap
navigableKeySet
Methods inherited from interface java.util.SortedMap
comparator, entrySet, values
-
Field Details
-
bounds
Key range bounds associated with this instance.
-
-
Constructor Details
-
AbstractNavigableMap
protected AbstractNavigableMap()Convenience constructor for the case where there are no lower or upper key bounds. -
AbstractNavigableMap
Primary constructor.- Parameters:
bounds
- key range restriction- Throws:
IllegalArgumentException
- ifbounds
is null
-
-
Method Details
-
getBounds
Get theBounds
associated with this instance.- Returns:
- range restriction
-
remove
Removes the mapping for a key from this map if it is present.The implementation in
AbstractNavigableMap
always throwsUnsupportedOperationException
. -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V> - Overrides:
containsKey
in classAbstractMap<K,
V>
-
firstKey
-
lastKey
-
keySet
-
lowerEntry
- Specified by:
lowerEntry
in interfaceNavigableMap<K,
V>
-
floorEntry
- Specified by:
floorEntry
in interfaceNavigableMap<K,
V>
-
ceilingEntry
- Specified by:
ceilingEntry
in interfaceNavigableMap<K,
V>
-
higherEntry
- Specified by:
higherEntry
in interfaceNavigableMap<K,
V>
-
lowerKey
- Specified by:
lowerKey
in interfaceNavigableMap<K,
V>
-
floorKey
- Specified by:
floorKey
in interfaceNavigableMap<K,
V>
-
ceilingKey
- Specified by:
ceilingKey
in interfaceNavigableMap<K,
V>
-
higherKey
- Specified by:
higherKey
in interfaceNavigableMap<K,
V>
-
firstEntry
- Specified by:
firstEntry
in interfaceNavigableMap<K,
V>
-
lastEntry
- Specified by:
lastEntry
in interfaceNavigableMap<K,
V>
-
pollFirstEntry
- Specified by:
pollFirstEntry
in interfaceNavigableMap<K,
V>
-
pollLastEntry
- Specified by:
pollLastEntry
in interfaceNavigableMap<K,
V>
-
descendingMap
- Specified by:
descendingMap
in interfaceNavigableMap<K,
V>
-
descendingKeySet
- Specified by:
descendingKeySet
in interfaceNavigableMap<K,
V>
-
subMap
-
headMap
-
tailMap
-
headMap
- Specified by:
headMap
in interfaceNavigableMap<K,
V>
-
tailMap
- Specified by:
tailMap
in interfaceNavigableMap<K,
V>
-
subMap
public NavigableMap<K,V> subMap(K newMinKey, boolean minInclusive, K newMaxKey, boolean maxInclusive) - Specified by:
subMap
in interfaceNavigableMap<K,
V>
-
searchBelow
Search for a lower element. Used to implementfloorEntry()
andlowerEntry()
.The implementation in
AbstractNavigableMap
checks the bounds then returns the first entry from a head map.- Parameters:
maxKey
- upper limit for searchinclusive
- true ifmaxKey
itself is a candidate- Returns:
- highest element below
maxKey
, or null if not found
-
searchAbove
Search for a higher element. Used to implementceilingEntry()
andhigherEntry()
.The implementation in
AbstractNavigableMap
checks the bounds then returns the first entry from a tail map.- Parameters:
minKey
- lower limit for searchinclusive
- true ifminKey
itself is a candidate- Returns:
- lowest element above
minKey
, 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
-
createSubMap
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 map'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
AbstractNavigableMap
returnsthis.bounds.isWithinLowerBound(this.comparator(), elem)
.- Parameters:
key
- map key- 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
AbstractNavigableMap
returnsthis.bounds.isWithinUpperBound(this.comparator(), elem)
.- Parameters:
key
- map key- Returns:
- true if
elem
is within this instance's upper bound, or this instance has no upper bound
-