K
- key typeV
- value typepublic abstract class AbstractNavigableMap<K,V> extends AbstractMap<K,V> implements NavigableMap<K,V>
NavigableMap
implementations.
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.
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Modifier and Type | Field and Description |
---|---|
protected Bounds<K> |
bounds
Key range bounds associated with this instance.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractNavigableMap()
Convenience constructor for the case where there are no lower or upper key bounds.
|
protected |
AbstractNavigableMap(Bounds<K> bounds)
Primary constructor.
|
Modifier and Type | Method and Description |
---|---|
Map.Entry<K,V> |
ceilingEntry(K minKey) |
K |
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.
|
NavigableSet<K> |
descendingKeySet() |
NavigableMap<K,V> |
descendingMap() |
Map.Entry<K,V> |
firstEntry() |
K |
firstKey() |
Map.Entry<K,V> |
floorEntry(K maxKey) |
K |
floorKey(K maxKey) |
protected Comparator<? super K> |
getComparator(boolean reversed)
Get a non-null
Comparator that sorts consistently with, and optionally reversed from, this instance. |
NavigableMap<K,V> |
headMap(K maxKey) |
NavigableMap<K,V> |
headMap(K newMaxKey,
boolean inclusive) |
Map.Entry<K,V> |
higherEntry(K minKey) |
K |
higherKey(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).
|
NavigableSet<K> |
keySet() |
Map.Entry<K,V> |
lastEntry() |
K |
lastKey() |
Map.Entry<K,V> |
lowerEntry(K maxKey) |
K |
lowerKey(K maxKey) |
Map.Entry<K,V> |
pollFirstEntry() |
Map.Entry<K,V> |
pollLastEntry() |
V |
remove(Object key)
Removes the mapping for a key from this map if it is present.
|
protected Map.Entry<K,V> |
searchAbove(K minKey,
boolean inclusive)
Search for a higher element.
|
protected Map.Entry<K,V> |
searchBelow(K maxKey,
boolean inclusive)
Search for a lower element.
|
NavigableMap<K,V> |
subMap(K newMinKey,
boolean minInclusive,
K newMaxKey,
boolean maxInclusive) |
NavigableMap<K,V> |
subMap(K minKey,
K maxKey) |
NavigableMap<K,V> |
tailMap(K minKey) |
NavigableMap<K,V> |
tailMap(K newMinKey,
boolean inclusive) |
clear, clone, containsValue, entrySet, equals, get, hashCode, put, putAll, size, toString, values
finalize, getClass, notify, notifyAll, wait, wait, wait
navigableKeySet
comparator, entrySet, values
clear, compute, computeIfAbsent, computeIfPresent, containsValue, equals, forEach, get, getOrDefault, hashCode, merge, put, putAll, putIfAbsent, remove, replace, replace, replaceAll, size
protected AbstractNavigableMap()
protected AbstractNavigableMap(Bounds<K> bounds)
bounds
- key range restrictionIllegalArgumentException
- if bounds
is nullpublic V remove(Object key)
The implementation in AbstractNavigableMap
always throws UnsupportedOperationException
.
public boolean isEmpty()
public boolean containsKey(Object obj)
containsKey
in interface Map<K,V>
containsKey
in class AbstractMap<K,V>
public NavigableSet<K> keySet()
public Map.Entry<K,V> lowerEntry(K maxKey)
lowerEntry
in interface NavigableMap<K,V>
public Map.Entry<K,V> floorEntry(K maxKey)
floorEntry
in interface NavigableMap<K,V>
public Map.Entry<K,V> ceilingEntry(K minKey)
ceilingEntry
in interface NavigableMap<K,V>
public Map.Entry<K,V> higherEntry(K minKey)
higherEntry
in interface NavigableMap<K,V>
public K ceilingKey(K minKey)
ceilingKey
in interface NavigableMap<K,V>
public Map.Entry<K,V> firstEntry()
firstEntry
in interface NavigableMap<K,V>
public Map.Entry<K,V> pollFirstEntry()
pollFirstEntry
in interface NavigableMap<K,V>
public Map.Entry<K,V> pollLastEntry()
pollLastEntry
in interface NavigableMap<K,V>
public NavigableMap<K,V> descendingMap()
descendingMap
in interface NavigableMap<K,V>
public NavigableSet<K> descendingKeySet()
descendingKeySet
in interface NavigableMap<K,V>
public NavigableMap<K,V> subMap(K minKey, K maxKey)
public NavigableMap<K,V> headMap(K maxKey)
public NavigableMap<K,V> tailMap(K minKey)
public NavigableMap<K,V> headMap(K newMaxKey, boolean inclusive)
headMap
in interface NavigableMap<K,V>
public NavigableMap<K,V> tailMap(K newMinKey, boolean inclusive)
tailMap
in interface NavigableMap<K,V>
public NavigableMap<K,V> subMap(K newMinKey, boolean minInclusive, K newMaxKey, boolean maxInclusive)
subMap
in interface NavigableMap<K,V>
protected Map.Entry<K,V> searchBelow(K maxKey, boolean inclusive)
floorEntry()
and lowerEntry()
.
The implementation in AbstractNavigableMap
checks the bounds then returns the first entry from a head map.
maxKey
- upper limit for searchinclusive
- true if maxKey
itself is a candidatemaxKey
, or null if not foundprotected Map.Entry<K,V> searchAbove(K minKey, boolean inclusive)
ceilingEntry()
and higherEntry()
.
The implementation in AbstractNavigableMap
checks the bounds then returns the first entry from a tail map.
minKey
- lower limit for searchinclusive
- true if minKey
itself is a candidateminKey
, or null if not foundprotected Comparator<? super K> getComparator(boolean reversed)
Comparator
that sorts consistently with, and optionally reversed from, this instance.reversed
- whether to return a reversed Comparator
Comparator
protected abstract NavigableMap<K,V> createSubMap(boolean reverse, Bounds<K> 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 map'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(K key)
The implementation in AbstractNavigableMap
returns this.bounds.isWithinLowerBound(this.comparator(), elem)
.
key
- map keyelem
is within this instance's lower bound, or this instance has no lower boundprotected boolean isWithinUpperBound(K key)
The implementation in AbstractNavigableMap
returns this.bounds.isWithinUpperBound(this.comparator(), elem)
.
key
- map keyelem
is within this instance's upper bound, or this instance has no upper boundCopyright © 2022. All rights reserved.