Added in API level 9

ConcurrentNavigableMap

interface ConcurrentNavigableMap<K : Any!, V : Any!> : ConcurrentMap<K, V>, NavigableMap<K, V>
ConcurrentSkipListMap

A scalable concurrent ConcurrentNavigableMap implementation.

A ConcurrentMap supporting NavigableMap operations, and recursively so for its navigable sub-maps.

This interface is a member of the Java Collections Framework.

Summary

Public methods
abstract NavigableSet<K>

Returns a reverse order NavigableSet view of the keys contained in this map.

abstract ConcurrentNavigableMap<K, V>

Returns a reverse order view of the mappings contained in this map.

abstract ConcurrentNavigableMap<K, V>
headMap(toKey: K)

abstract ConcurrentNavigableMap<K, V>
headMap(toKey: K, inclusive: Boolean)

abstract NavigableSet<K>

Returns a NavigableSet view of the keys contained in this map.

abstract ConcurrentNavigableMap<K, V>
subMap(fromKey: K, fromInclusive: Boolean, toKey: K, toInclusive: Boolean)

abstract ConcurrentNavigableMap<K, V>
subMap(fromKey: K, toKey: K)

abstract ConcurrentNavigableMap<K, V>
tailMap(fromKey: K)

abstract ConcurrentNavigableMap<K, V>
tailMap(fromKey: K, inclusive: Boolean)

Inherited functions
MutableEntry<K, V>? ceilingEntry(key: K)

Returns a key-value mapping associated with the least key greater than or equal to the given key, or null if there is no such key.

K? ceilingKey(key: K)

Returns the least key greater than or equal to the given key, or null if there is no such key.

MutableEntry<K, V>? firstEntry()

Returns a key-value mapping associated with the least key in this map, or null if the map is empty.

MutableEntry<K, V>? floorEntry(key: K)

Returns a key-value mapping associated with the greatest key less than or equal to the given key, or null if there is no such key.

K? floorKey(key: K)

Returns the greatest key less than or equal to the given key, or null if there is no such key.

MutableEntry<K, V>? higherEntry(key: K)

Returns a key-value mapping associated with the least key strictly greater than the given key, or null if there is no such key.

K? higherKey(key: K)

Returns the least key strictly greater than the given key, or null if there is no such key.

MutableEntry<K, V>? lastEntry()

Returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.

MutableEntry<K, V>? lowerEntry(key: K)

Returns a key-value mapping associated with the greatest key strictly less than the given key, or null if there is no such key.

K? lowerKey(key: K)

Returns the greatest key strictly less than the given key, or null if there is no such key.

MutableEntry<K, V>? pollFirstEntry()

Removes and returns a key-value mapping associated with the least key in this map, or null if the map is empty.

MutableEntry<K, V>? pollLastEntry()

Removes and returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.

NavigableMap<K, V> reversed()

Returns a reverse-ordered view of this map. The encounter order of mappings in the returned view is the inverse of the encounter order of mappings in this map. The reverse ordering affects all order-sensitive operations, including those on the view collections of the returned view. If the implementation permits modifications to this view, the modifications "write through" to the underlying map. Changes to the underlying map might or might not be visible in this reversed view, depending upon the implementation.

This method is equivalent to descendingMap.

Comparator<in K>? comparator()

Returns the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys.

K firstKey()

Returns the first (lowest) key currently in this map.

K lastKey()

Returns the last (highest) key currently in this map.

V? putFirst(k: K, v: V)

Throws UnsupportedOperationException. The encounter order induced by this map's comparison method determines the position of mappings, so explicit positioning is not supported.

V? putLast(k: K, v: V)

Throws UnsupportedOperationException. The encounter order induced by this map's comparison method determines the position of mappings, so explicit positioning is not supported.

V? compute(key: K, remappingFunction: BiFunction<in K, in V?, out V?>)

Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping). For example, to either create or append a String msg to a value mapping:

<code>map.compute(key, (k, v) -&gt; (v == null) ? msg : v.concat(msg))</code>
(Method merge() is often simpler to use for such purposes.)

If the remapping function returns null, the mapping is removed (or remains absent if initially absent). If the remapping function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.

The remapping function should not modify this map during computation.

V computeIfAbsent(key: K, mappingFunction: Function<in K, out V>)

If the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function and enters it into this map unless null.

If the mapping function returns null, no mapping is recorded. If the mapping function itself throws an (unchecked) exception, the exception is rethrown, and no mapping is recorded. The most common usage is to construct a new object serving as an initial mapped value or memoized result, as in:

<code>map.computeIfAbsent(key, k -&gt; new Value(f(k)));
  </code>

Or to implement a multi-value map, Map<K,Collection<V>>, supporting multiple values per key:

<code>map.computeIfAbsent(key, k -&gt; new HashSet&lt;V&gt;()).add(v);
  </code>

The mapping function should not modify this map during computation.

V? computeIfPresent(key: K, remappingFunction: BiFunction<in K, in V, out V?>)

If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value.

If the remapping function returns null, the mapping is removed. If the remapping function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.

The remapping function should not modify this map during computation.

Unit forEach(action: BiConsumer<in K, in V>)

Performs the given action for each entry in this map until all entries have been processed or the action throws an exception. Unless otherwise specified by the implementing class, actions are performed in the order of entry set iteration (if an iteration order is specified.) Exceptions thrown by the action are relayed to the caller.

V getOrDefault(key: K, defaultValue: V)

Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.

V? merge(key: K, value: V, remappingFunction: BiFunction<in V, in V, out V?>)

If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value. Otherwise, replaces the associated value with the results of the given remapping function, or removes if the result is null. This method may be of use when combining multiple mapped values for a key. For example, to either create or append a String msg to a value mapping:

<code>map.merge(key, msg, String::concat)
  </code>

If the remapping function returns null, the mapping is removed. If the remapping function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.

The remapping function should not modify this map during computation.

V? putIfAbsent(key: K, value: V)

If the specified key is not already associated with a value, associates it with the given value. This is equivalent to, for this map:

<code>if (!map.containsKey(key))
    return map.put(key, value);
  else
    return map.get(key);</code>
except that the action is performed atomically.

Boolean remove(key: K, value: V)

Removes the entry for a key only if currently mapped to a given value. This is equivalent to, for this map:

<code>if (map.containsKey(key)
      &amp;&amp; Objects.equals(map.get(key), value)) {
    map.remove(key);
    return true;
  } else {
    return false;
  }</code>
except that the action is performed atomically.

V? replace(key: K, value: V)

Replaces the entry for a key only if currently mapped to some value. This is equivalent to, for this map:

<code>if (map.containsKey(key))
    return map.put(key, value);
  else
    return null;</code>
except that the action is performed atomically.

Boolean replace(key: K, oldValue: V, newValue: V)

Replaces the entry for a key only if currently mapped to a given value. This is equivalent to, for this map:

<code>if (map.containsKey(key)
      &amp;&amp; Objects.equals(map.get(key), oldValue)) {
    map.put(key, newValue);
    return true;
  } else {
    return false;
  }</code>
except that the action is performed atomically.

Unit replaceAll(function: BiFunction<in K, in V, out V>)

Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception. Exceptions thrown by the function are relayed to the caller.

MutableEntry<K, V>! firstEntry()

Returns the first key-value mapping in this map, or null if the map is empty.

MutableEntry<K, V>! lastEntry()

Returns the last key-value mapping in this map, or null if the map is empty.

MutableEntry<K, V>! pollFirstEntry()

Removes and returns the first key-value mapping in this map, or null if the map is empty (optional operation).

MutableEntry<K, V>! pollLastEntry()

Removes and returns the last key-value mapping in this map, or null if the map is empty (optional operation).

SequencedSet<MutableEntry<K, V>!>! sequencedEntrySet()

Returns a SequencedSet view of this map's entrySet.

SequencedSet<K>! sequencedKeySet()

Returns a SequencedSet view of this map's keySet.

SequencedCollection<V>! sequencedValues()

Returns a SequencedCollection view of this map's values collection.

Properties
abstract NavigableSet<K>

Returns a NavigableSet view of the keys contained in this map.

Inherited properties
MutableSet<MutableEntry<K, V>> entries

Returns a Set view of the mappings contained in this map. The set's iterator returns the entries in ascending key order. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

MutableSet<K> keys

Returns a Set view of the keys contained in this map. The set's iterator returns the keys in ascending order. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

MutableCollection<V> values

Returns a Collection view of the values contained in this map. The collection's iterator returns the values in ascending order of the corresponding keys. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Public methods

descendingKeySet

Added in API level 9
abstract fun descendingKeySet(): NavigableSet<K>

Returns a reverse order NavigableSet view of the keys contained in this map. The set's iterator returns the keys in descending order. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

The view's iterators and spliterators are weakly consistent.

Return
NavigableSet<K> a reverse order navigable set view of the keys in this map

descendingMap

Added in API level 9
abstract fun descendingMap(): ConcurrentNavigableMap<K, V>

Returns a reverse order view of the mappings contained in this map. The descending map is backed by this map, so changes to the map are reflected in the descending map, and vice-versa.

The returned map has an ordering equivalent to java.util.Collections#reverseOrder(Comparator)(comparator()). The expression m.descendingMap().descendingMap() returns a view of m essentially equivalent to m.

Return
ConcurrentNavigableMap<K, V> a reverse order view of this map

headMap

Added in API level 9
abstract fun headMap(toKey: K): ConcurrentNavigableMap<K, V>
Parameters
toKey K: high endpoint (exclusive) of the keys in the returned map
Return
ConcurrentNavigableMap<K, V> a view of the portion of this map whose keys are strictly less than toKey
Exceptions
java.lang.ClassCastException if toKey is not compatible with this map's comparator (or, if the map has no comparator, if toKey does not implement Comparable). Implementations may, but are not required to, throw this exception if toKey cannot be compared to keys currently in the map.
java.lang.NullPointerException if toKey is null and this map does not permit null keys
java.lang.IllegalArgumentException if this map itself has a restricted range, and toKey lies outside the bounds of the range

headMap

Added in API level 9
abstract fun headMap(
    toKey: K,
    inclusive: Boolean
): ConcurrentNavigableMap<K, V>
Parameters
toKey K: high endpoint of the keys in the returned map
inclusive Boolean: true if the high endpoint is to be included in the returned view
Return
ConcurrentNavigableMap<K, V> a view of the portion of this map whose keys are less than (or equal to, if inclusive is true) toKey
Exceptions
java.lang.ClassCastException if toKey is not compatible with this map's comparator (or, if the map has no comparator, if toKey does not implement Comparable). Implementations may, but are not required to, throw this exception if toKey cannot be compared to keys currently in the map.
java.lang.NullPointerException if toKey is null and this map does not permit null keys
java.lang.IllegalArgumentException if this map itself has a restricted range, and toKey lies outside the bounds of the range
Added in API level 9
abstract fun navigableKeySet(): NavigableSet<K>

Returns a NavigableSet view of the keys contained in this map. The set's iterator returns the keys in ascending order. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

The view's iterators and spliterators are weakly consistent.

Return
NavigableSet<K> a navigable set view of the keys in this map

subMap

Added in API level 9
abstract fun subMap(
    fromKey: K,
    fromInclusive: Boolean,
    toKey: K,
    toInclusive: Boolean
): ConcurrentNavigableMap<K, V>
Parameters
fromKey K: low endpoint of the keys in the returned map
fromInclusive Boolean: true if the low endpoint is to be included in the returned view
toKey K: high endpoint of the keys in the returned map
toInclusive Boolean: true if the high endpoint is to be included in the returned view
Return
ConcurrentNavigableMap<K, V> a view of the portion of this map whose keys range from fromKey to toKey
Exceptions
java.lang.ClassCastException if fromKey and toKey cannot be compared to one another using this map's comparator (or, if the map has no comparator, using natural ordering). Implementations may, but are not required to, throw this exception if fromKey or toKey cannot be compared to keys currently in the map.
java.lang.NullPointerException if fromKey or toKey is null and this map does not permit null keys
java.lang.IllegalArgumentException if fromKey is greater than toKey; or if this map itself has a restricted range, and fromKey or toKey lies outside the bounds of the range

subMap

Added in API level 9
abstract fun subMap(
    fromKey: K,
    toKey: K
): ConcurrentNavigableMap<K, V>
Parameters
fromKey K: low endpoint (inclusive) of the keys in the returned map
toKey K: high endpoint (exclusive) of the keys in the returned map
Return
ConcurrentNavigableMap<K, V> a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive
Exceptions
java.lang.ClassCastException if fromKey and toKey cannot be compared to one another using this map's comparator (or, if the map has no comparator, using natural ordering). Implementations may, but are not required to, throw this exception if fromKey or toKey cannot be compared to keys currently in the map.
java.lang.NullPointerException if fromKey or toKey is null and this map does not permit null keys
java.lang.IllegalArgumentException if fromKey is greater than toKey; or if this map itself has a restricted range, and fromKey or toKey lies outside the bounds of the range

tailMap

Added in API level 9
abstract fun tailMap(fromKey: K): ConcurrentNavigableMap<K, V>
Parameters
fromKey K: low endpoint (inclusive) of the keys in the returned map
Return
ConcurrentNavigableMap<K, V> a view of the portion of this map whose keys are greater than or equal to fromKey
Exceptions
java.lang.ClassCastException if fromKey is not compatible with this map's comparator (or, if the map has no comparator, if fromKey does not implement Comparable). Implementations may, but are not required to, throw this exception if fromKey cannot be compared to keys currently in the map.
java.lang.NullPointerException if fromKey is null and this map does not permit null keys
java.lang.IllegalArgumentException if this map itself has a restricted range, and fromKey lies outside the bounds of the range

tailMap

Added in API level 9
abstract fun tailMap(
    fromKey: K,
    inclusive: Boolean
): ConcurrentNavigableMap<K, V>
Parameters
fromKey K: low endpoint of the keys in the returned map
inclusive Boolean: true if the low endpoint is to be included in the returned view
Return
ConcurrentNavigableMap<K, V> a view of the portion of this map whose keys are greater than (or equal to, if inclusive is true) fromKey
Exceptions
java.lang.ClassCastException if fromKey is not compatible with this map's comparator (or, if the map has no comparator, if fromKey does not implement Comparable). Implementations may, but are not required to, throw this exception if fromKey cannot be compared to keys currently in the map.
java.lang.NullPointerException if fromKey is null and this map does not permit null keys
java.lang.IllegalArgumentException if this map itself has a restricted range, and fromKey lies outside the bounds of the range

Properties

keys

Added in API level 9
abstract val keys: NavigableSet<K>

Returns a NavigableSet view of the keys contained in this map. The set's iterator returns the keys in ascending order. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

The view's iterators and spliterators are weakly consistent.

This method is equivalent to method navigableKeySet.

Return
NavigableSet<K> a navigable set view of the keys in this map