K
- the type of keys in the mapV
- the type of values in the mappublic abstract class AbstractRandomAccessNavigableMap<K,V> extends AbstractNavigableMap<K,V> implements RandomAccessNavigableMap<K,V>
RandomAccessNavigableMap
implementations. Sub-classes must
implement most of the methods needed to implement a normal AbstractNavigableMap
. The
main differences follow:
firstEntry()
and lastEntry()
do not need to be implemented. This
abstract map implements them in terms of random access, e.g. getEntry(0)
RandomAccessNavigableMap.getEntry(int)
and RandomAccessNavigableMap.removeEntry(int)
, must be
implemented.AbstractNavigableMap.BaseIteratorImpl<T>, AbstractNavigableMap.DescendingKeyIteratorImpl, AbstractNavigableMap.EntryIteratorImpl, AbstractNavigableMap.EntrySet, AbstractNavigableMap.KeyIteratorImpl, AbstractNavigableMap.KeySet, AbstractNavigableMap.SubMap, AbstractNavigableMap.ValueCollection, AbstractNavigableMap.ValueIteratorImpl
comparator, modCount
Modifier | Constructor and Description |
---|---|
protected |
AbstractRandomAccessNavigableMap()
Constructs a new, empty map that orders keys according to their natural
ordering.
|
protected |
AbstractRandomAccessNavigableMap(Comparator<? super K> comparator)
Constructs a new, empty map that orders keys using the specified comparator.
|
Modifier and Type | Method and Description |
---|---|
RandomAccessNavigableSet<K> |
descendingKeySet() |
RandomAccessNavigableMap<K,V> |
descendingMap() |
RandomAccessSet<Map.Entry<K,V>> |
entrySet() |
Map.Entry<K,V> |
firstEntry() |
RandomAccessNavigableMap<K,V> |
headMap(K toKey) |
RandomAccessNavigableMap<K,V> |
headMap(K toKey,
boolean inclusive) |
int |
indexOfKey(Object key)
Determines the random access index at which the given key is found in the map.
|
RandomAccessSet<K> |
keySet() |
Map.Entry<K,V> |
lastEntry() |
ListIterator<Map.Entry<K,V>> |
listIterator()
Returns a list iterator that can iterator backwards and forwards over the set of mappings.
|
ListIterator<Map.Entry<K,V>> |
listIterator(int index)
Returns a list iterator that can iterator backwards and forwards over the set of mappings,
starting at a given index into the set.
|
RandomAccessNavigableSet<K> |
navigableKeySet() |
protected void |
rangeCheck(int index)
Checks that the specified index is greater than or equal to zero and less than this map's
Map.size() . |
protected void |
rangeCheckWide(int index)
Checks that the specified index is greater than or equal to zero and less than or equal to
this map's
Map.size() . |
RandomAccessNavigableMap<K,V> |
subMap(K fromKey,
boolean fromInclusive,
K toKey,
boolean toInclusive) |
RandomAccessNavigableMap<K,V> |
subMap(K fromKey,
K toKey) |
RandomAccessNavigableMap<K,V> |
subMapByIndices(int startIndex,
int endIndex)
Returns a view of a region of this map.
|
RandomAccessNavigableMap<K,V> |
tailMap(K fromKey) |
RandomAccessNavigableMap<K,V> |
tailMap(K fromKey,
boolean inclusive) |
List<V> |
values() |
ceilingEntry, ceilingKey, clear, comparator, containsKey, containsValue, equals, firstKey, floorEntry, floorKey, get, getEntry, getModCount, hashCode, higherKey, isEmpty, lastKey, lowerKey, pollFirstEntry, pollLastEntry, putAll, remove, removeEntry, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getEntry, removeEntry
ceilingEntry, ceilingKey, floorEntry, floorKey, higherEntry, higherKey, lowerEntry, lowerKey, pollFirstEntry, pollLastEntry
comparator, firstKey, lastKey
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, equals, forEach, get, getOrDefault, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size
protected AbstractRandomAccessNavigableMap()
protected AbstractRandomAccessNavigableMap(Comparator<? super K> comparator)
comparator
- determines ordering of keys in the mapprotected void rangeCheck(int index)
Map.size()
.index
- an index to checkprotected void rangeCheckWide(int index)
Map.size()
. This is for certain operations where an index equal to the size
(after the last valid index in the map) is allowed.index
- an index to checkpublic int indexOfKey(Object key)
RandomAccessNavigableMap
indexOfKey
in interface RandomAccessNavigableMap<K,V>
key
- a keypublic ListIterator<Map.Entry<K,V>> listIterator()
RandomAccessNavigableMap
listIterator
in interface RandomAccessNavigableMap<K,V>
public ListIterator<Map.Entry<K,V>> listIterator(int index)
RandomAccessNavigableMap
listIterator
in interface RandomAccessNavigableMap<K,V>
index
- a random access indexpublic Map.Entry<K,V> firstEntry()
firstEntry
in interface NavigableMap<K,V>
public RandomAccessNavigableMap<K,V> subMapByIndices(int startIndex, int endIndex)
RandomAccessNavigableMap
RandomAccessNavigableMap.subMap(K, boolean, K, boolean)
, this bounds of this region are
defined by random access indices instead of key values.subMapByIndices
in interface RandomAccessNavigableMap<K,V>
startIndex
- the starting index, inclusive, of the regionendIndex
- the ending index, exclusive, of the regionpublic RandomAccessSet<K> keySet()
AbstractNavigableMap
This default implementation delegates to AbstractNavigableMap.navigableKeySet()
.
public List<V> values()
AbstractNavigableMap
This default implementation returns a AbstractNavigableMap.ValueCollection
.
public RandomAccessSet<Map.Entry<K,V>> entrySet()
AbstractNavigableMap
This default implementation returns an AbstractNavigableMap.EntrySet
.
public RandomAccessNavigableMap<K,V> descendingMap()
AbstractNavigableMap
This default implementation should suffice for any NavigableMap
since the map
provides all necessary operations to trivially reverse the order. It simply uses inverse
operations to return the descending view of this map. For example, the inverse of
NavigableMap.firstEntry()
is NavigableMap.lastEntry()
, the inverse of the key set's
iterator()
is its descendingIterator()
, etc.
descendingMap
in interface RandomAccessNavigableMap<K,V>
descendingMap
in interface NavigableMap<K,V>
descendingMap
in class AbstractNavigableMap<K,V>
public RandomAccessNavigableSet<K> navigableKeySet()
AbstractNavigableMap
This default implementation returns a AbstractNavigableMap.KeySet
.
navigableKeySet
in interface RandomAccessNavigableMap<K,V>
navigableKeySet
in interface NavigableMap<K,V>
navigableKeySet
in class AbstractNavigableMap<K,V>
public RandomAccessNavigableSet<K> descendingKeySet()
AbstractNavigableMap
This default implementation returns AbstractNavigableMap.navigableKeySet()
.descendingSet()
.
descendingKeySet
in interface RandomAccessNavigableMap<K,V>
descendingKeySet
in interface NavigableMap<K,V>
descendingKeySet
in class AbstractNavigableMap<K,V>
public RandomAccessNavigableMap<K,V> subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)
AbstractNavigableMap
This default implementation returns a AbstractNavigableMap.SubMap
with the specified bounds.
subMap
in interface RandomAccessNavigableMap<K,V>
subMap
in interface NavigableMap<K,V>
subMap
in class AbstractNavigableMap<K,V>
public RandomAccessNavigableMap<K,V> headMap(K toKey, boolean inclusive)
AbstractNavigableMap
This default implementation returns a AbstractNavigableMap.SubMap
with the specified upper bound and
no lower bound.
headMap
in interface RandomAccessNavigableMap<K,V>
headMap
in interface NavigableMap<K,V>
headMap
in class AbstractNavigableMap<K,V>
public RandomAccessNavigableMap<K,V> tailMap(K fromKey, boolean inclusive)
AbstractNavigableMap
This default implementation returns a AbstractNavigableMap.SubMap
with the specified lower bound and
no upper bound.
tailMap
in interface RandomAccessNavigableMap<K,V>
tailMap
in interface NavigableMap<K,V>
tailMap
in class AbstractNavigableMap<K,V>
public RandomAccessNavigableMap<K,V> subMap(K fromKey, K toKey)
AbstractNavigableMap
This default implementation simply calls subMap(fromKey, true, toKey, false)
. The return type is also overridden to provide access to
the full NavigableMap
interface of the returned view.
public RandomAccessNavigableMap<K,V> headMap(K toKey)
AbstractNavigableMap
This default implementation simply calls headMap(toKey, false)
. The return type is also overridden to provide access to
the full NavigableMap
interface of the returned view.
public RandomAccessNavigableMap<K,V> tailMap(K fromKey)
AbstractNavigableMap
This default implementation simply calls tailMap(fromKey, true)
. The return type is also overridden to provide access to
the full NavigableMap
interface of the returned view.