ConcurrentSkipListMap
open class ConcurrentSkipListMap<K : Any!, V : Any!> : AbstractMap<K, V>, Cloneable, ConcurrentNavigableMap<K, V>, Serializable, MutableMap<K, V>
A scalable concurrent ConcurrentNavigableMap
implementation. The map is sorted according to the ordering of its keys, or by a Comparator
provided at map creation time, depending on which constructor is used.
This class implements a concurrent variant of SkipLists providing expected average log(n) time cost for the containsKey
, get
, put
and remove
operations and their variants. Insertion, removal, update, and access operations safely execute concurrently by multiple threads.
Iterators and spliterators are weakly consistent.
Ascending key ordered views and their iterators are faster than descending ones.
All Map.Entry
pairs returned by methods in this class and its views represent snapshots of mappings at the time they were produced. They do not support the Entry.setValue
method. (Note however that it is possible to change mappings in the associated map using put
, putIfAbsent
, or replace
, depending on exactly which effect you need.)
Beware that bulk operations putAll
, equals
, toArray
, containsValue
, and clear
are not guaranteed to be performed atomically. For example, an iterator operating concurrently with a putAll
operation might view only some of the added elements.
This class and its views and iterators implement all of the optional methods of the Map
and Iterator
interfaces. Like most other concurrent collections, this class does not permit the use of null
keys or values because some null return values cannot be reliably distinguished from the absence of elements.
This class is a member of the Java Collections Framework.
Summary
Public constructors |
Constructs a new, empty map, sorted according to the natural ordering of the keys.
|
Constructs a new, empty map, sorted according to the specified comparator.
|
Constructs a new map containing the same mappings as the given map, sorted according to the natural ordering of the keys.
|
Constructs a new map containing the same mappings and using the same ordering as the specified sorted map.
|
Public methods |
open MutableEntry<K, V>? |
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 entry.
|
open K? |
|
open Unit |
Removes all of the mappings from this map.
|
open ConcurrentSkipListMap<K, V> |
Returns a shallow copy of this ConcurrentSkipListMap instance.
|
open Comparator<in K>? |
|
open V? |
Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).
|
open V |
If the specified key is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this map unless null .
|
open V? |
If the value for the specified key is present, attempts to compute a new mapping given the key and its current mapped value.
|
open Boolean |
Returns true if this map contains a mapping for the specified key.
|
open Boolean |
Returns true if this map contains a mapping for the specified key.
|
open Boolean |
Returns true if this map maps one or more keys to the specified value.
|
open Boolean |
Returns true if this map maps one or more keys to the specified value.
|
open NavigableSet<K> |
|
open ConcurrentNavigableMap<K, V> |
|
open Boolean |
Compares the specified object with this map for equality.
|
open MutableEntry<K, V>? |
Returns a key-value mapping associated with the least key in this map, or null if the map is empty.
|
open K |
|
open MutableEntry<K, V>? |
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.
|
open K? |
|
open Unit |
|
open V? |
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
|
open V? |
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
|
open V |
Returns the value to which the specified key is mapped, or the given defaultValue if this map contains no mapping for the key.
|
open ConcurrentNavigableMap<K, V> |
|
open ConcurrentNavigableMap<K, V> |
|
open MutableEntry<K, V>? |
Returns a key-value mapping associated with the least key strictly greater than the given key, or null if there is no such key.
|
open K? |
|
open Boolean |
Returns true if this map contains no key-value mappings.
|
open MutableEntry<K, V>? |
Returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.
|
open K |
|
open MutableEntry<K, V>? |
Returns a key-value mapping associated with the greatest key strictly less than the given key, or null if there is no such key.
|
open K? |
|
open V? |
If the specified key is not already associated with a value, associates it with the given value.
|
open NavigableSet<K> |
|
open MutableEntry<K, V>? |
Removes and returns a key-value mapping associated with the least key in this map, or null if the map is empty.
|
open MutableEntry<K, V>? |
Removes and returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.
|
open V? |
Associates the specified value with the specified key in this map.
|
open V? |
Throws UnsupportedOperationException .
|
open V? |
If the specified key is not already associated with a value (or is mapped to null ) associates it with the given value and returns null , else returns the current value.
|
open V? |
Throws UnsupportedOperationException .
|
open V? |
Removes the mapping for the specified key from this map if present.
|
open Boolean |
Removes the entry for the specified key only if it is currently mapped to the specified value.
|
open V? |
Removes the mapping for the specified key from this map if present.
|
open V? |
Replaces the entry for the specified key only if it is currently mapped to some value.
|
open Boolean |
replace(key: K, oldValue: V, newValue: V)
Replaces the entry for the specified key only if currently mapped to the specified value.
|
open Unit |
|
open ConcurrentNavigableMap<K, V> |
|
open ConcurrentNavigableMap<K, V> |
|
open ConcurrentNavigableMap<K, V> |
|
open ConcurrentNavigableMap<K, V> |
|
Inherited functions |
From class AbstractMap
Int |
hashCode()
Returns the hash code value for this map. The hash code of a map is defined to be the sum of the hash codes of each entry in the map's entrySet() view. This ensures that m1.equals(m2) implies that m1.hashCode()==m2.hashCode() for any two maps m1 and m2 , as required by the general contract of Object.hashCode .
|
Unit |
putAll(from: Map<out K, V>)
Copies all of the mappings from the specified map to this map (optional operation). The effect of this call is equivalent to that of calling put(k, v) on this map once for each mapping from key k to value v in the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress. If the specified map has a defined encounter order, processing of its mappings generally occurs in that order.
|
String |
toString()
Returns a string representation of this map. The string representation consists of a list of key-value mappings in the order returned by the map's entrySet view's iterator, enclosed in braces ("{}" ). Adjacent mappings are separated by the characters ", " (comma and space). Each key-value mapping is rendered as the key followed by an equals sign ("=" ) followed by the associated value. Keys and values are converted to strings as by String.valueOf(Object) .
|
|
Public constructors
ConcurrentSkipListMap
ConcurrentSkipListMap()
Constructs a new, empty map, sorted according to the natural ordering of the keys.
ConcurrentSkipListMap
ConcurrentSkipListMap(comparator: Comparator<in K>!)
Constructs a new, empty map, sorted according to the specified comparator.
Parameters |
comparator |
Comparator<in K>!: the comparator that will be used to order this map. If null , the ordering of the keys will be used. |
ConcurrentSkipListMap
ConcurrentSkipListMap(m: MutableMap<out K, out V>!)
Constructs a new map containing the same mappings as the given map, sorted according to the natural ordering of the keys.
Parameters |
m |
MutableMap<out K, out V>!: the map whose mappings are to be placed in this map |
Exceptions |
java.lang.ClassCastException |
if the keys in m are not Comparable , or are not mutually comparable |
java.lang.NullPointerException |
if the specified map or any of its keys or values are null |
ConcurrentSkipListMap
ConcurrentSkipListMap(m: SortedMap<K, out V>!)
Constructs a new map containing the same mappings and using the same ordering as the specified sorted map.
Parameters |
m |
SortedMap<K, out V>!: the sorted map whose mappings are to be placed in this map, and whose comparator is to be used to sort this map |
Exceptions |
java.lang.NullPointerException |
if the specified sorted map or any of its keys or values are null |
Public methods
ceilingEntry
open fun ceilingEntry(key: K): MutableEntry<K, V>?
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 entry. The returned entry does not support the Entry.setValue
method.
Parameters |
key |
K: the key |
Return |
MutableEntry<K, V>? |
an entry with the least key greater than or equal to key , or null if there is no such key |
Exceptions |
java.lang.ClassCastException |
if the specified key cannot be compared with the keys currently in the map |
java.lang.NullPointerException |
if the specified key is null |
ceilingKey
open fun ceilingKey(key: K): K?
Parameters |
key |
K: the key |
Return |
K? |
the least key greater than or equal to key , or null if there is no such key |
Exceptions |
java.lang.ClassCastException |
if the specified key cannot be compared with the keys currently in the map |
java.lang.NullPointerException |
if the specified key is null |
clear
open fun clear(): Unit
Removes all of the mappings from this map.
Exceptions |
java.lang.UnsupportedOperationException |
if the clear operation is not supported by this map |
clone
open fun clone(): ConcurrentSkipListMap<K, V>
Returns a shallow copy of this ConcurrentSkipListMap
instance. (The keys and values themselves are not cloned.)
Exceptions |
java.lang.CloneNotSupportedException |
if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned. |
comparator
open fun comparator(): Comparator<in K>?
Return |
Comparator<in K>? |
the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys |
compute
open fun compute(
key: K,
remappingFunction: BiFunction<in K, in V?, out V?>
): V?
Attempts to compute a mapping for the specified key and its current mapped value (or null
if there is no current mapping). The function is NOT guaranteed to be applied once atomically.
Parameters |
key |
K: key with which the specified value is to be associated |
remappingFunction |
BiFunction<in K, in V?, out V?>: the function to compute a value |
Return |
V? |
the new value associated with the specified key, or null if none |
Exceptions |
java.lang.NullPointerException |
if the specified key is null or the remappingFunction is null |
java.lang.UnsupportedOperationException |
if the put operation is not supported by this map (java.util.Collection#) |
java.lang.ClassCastException |
if the class of the specified key or value prevents it from being stored in this map (java.util.Collection#) |
java.lang.IllegalArgumentException |
if some property of the specified key or value prevents it from being stored in this map (java.util.Collection#) |
computeIfAbsent
open fun computeIfAbsent(
key: K,
mappingFunction: Function<in K, out V>
): V
If the specified key is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this map unless null
. The function is NOT guaranteed to be applied once atomically only if the value is not present.
Parameters |
key |
K: key with which the specified value is to be associated |
mappingFunction |
Function<in K, out V>: the function to compute a value |
Return |
V |
the current (existing or computed) value associated with the specified key, or null if the computed value is null |
Exceptions |
java.lang.NullPointerException |
if the specified key is null or the mappingFunction is null |
java.lang.UnsupportedOperationException |
if the put operation is not supported by this map (java.util.Collection#) |
java.lang.ClassCastException |
if the class of the specified key or value prevents it from being stored in this map (java.util.Collection#) |
java.lang.IllegalArgumentException |
if some property of the specified key or value prevents it from being stored in this map (java.util.Collection#) |
computeIfPresent
open fun computeIfPresent(
key: K,
remappingFunction: BiFunction<in K, in V, out V?>
): V?
If the value for the specified key is present, attempts to compute a new mapping given the key and its current mapped value. The function is NOT guaranteed to be applied once atomically.
Parameters |
key |
K: key with which a value may be associated |
remappingFunction |
BiFunction<in K, in V, out V?>: the function to compute a value |
Return |
V? |
the new value associated with the specified key, or null if none |
Exceptions |
java.lang.NullPointerException |
if the specified key is null or the remappingFunction is null |
java.lang.UnsupportedOperationException |
if the put operation is not supported by this map (java.util.Collection#) |
java.lang.ClassCastException |
if the class of the specified key or value prevents it from being stored in this map (java.util.Collection#) |
java.lang.IllegalArgumentException |
if some property of the specified key or value prevents it from being stored in this map (java.util.Collection#) |
containsKey
open fun containsKey(key: K): Boolean
Returns true
if this map contains a mapping for the specified key.
Parameters |
key |
K: key whose presence in this map is to be tested |
Return |
Boolean |
true if this map contains a mapping for the specified key |
Exceptions |
java.lang.ClassCastException |
if the specified key cannot be compared with the keys currently in the map |
java.lang.NullPointerException |
if the specified key is null |
containsKey
open fun containsKey(key: K): Boolean
Returns true
if this map contains a mapping for the specified key.
Parameters |
key |
K: key whose presence in this map is to be tested |
Return |
Boolean |
true if this map contains a mapping for the specified key |
Exceptions |
java.lang.ClassCastException |
if the specified key cannot be compared with the keys currently in the map |
java.lang.NullPointerException |
if the specified key is null |
containsValue
open fun containsValue(value: V): Boolean
Returns true
if this map maps one or more keys to the specified value. This operation requires time linear in the map size. Additionally, it is possible for the map to change during execution of this method, in which case the returned result may be inaccurate.
Parameters |
value |
V: value whose presence in this map is to be tested |
Return |
Boolean |
true if a mapping to value exists; false otherwise |
Exceptions |
java.lang.ClassCastException |
if the value is of an inappropriate type for this map (java.util.Collection#) |
java.lang.NullPointerException |
if the specified value is null |
containsValue
open fun containsValue(value: V): Boolean
Returns true
if this map maps one or more keys to the specified value. This operation requires time linear in the map size. Additionally, it is possible for the map to change during execution of this method, in which case the returned result may be inaccurate.
Parameters |
value |
V: value whose presence in this map is to be tested |
Return |
Boolean |
true if a mapping to value exists; false otherwise |
Exceptions |
java.lang.ClassCastException |
if the value is of an inappropriate type for this map (java.util.Collection#) |
java.lang.NullPointerException |
if the specified value is null |
descendingKeySet
open fun descendingKeySet(): NavigableSet<K>
Return |
NavigableSet<K> |
a reverse order navigable set view of the keys in this map |
equals
open fun equals(other: Any?): Boolean
Compares the specified object with this map for equality. Returns true
if the given object is also a map and the two maps represent the same mappings. More formally, two maps m1
and m2
represent the same mappings if m1.entrySet().equals(m2.entrySet())
. This operation may return misleading results if either map is concurrently modified during execution of this method.
Parameters |
obj |
the reference object with which to compare. |
o |
object to be compared for equality with this map |
Return |
Boolean |
true if the specified object is equal to this map |
firstEntry
open fun firstEntry(): MutableEntry<K, V>?
Returns a key-value mapping associated with the least key in this map, or null
if the map is empty. The returned entry does not support the Entry.setValue
method.
Return |
MutableEntry<K, V>? |
an entry with the least key, or null if this map is empty |
firstKey
open fun firstKey(): K
Return |
K |
the first (lowest) key currently in this map |
Exceptions |
java.util.NoSuchElementException |
if this map is empty |
floorEntry
open fun floorEntry(key: K): MutableEntry<K, V>?
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. The returned entry does not support the Entry.setValue
method.
Parameters |
key |
K: the key |
Return |
MutableEntry<K, V>? |
an entry with the greatest key less than or equal to key , or null if there is no such key |
Exceptions |
java.lang.ClassCastException |
if the specified key cannot be compared with the keys currently in the map |
java.lang.NullPointerException |
if the specified key is null |
floorKey
open fun floorKey(key: K): K?
Parameters |
key |
K: the key |
Return |
K? |
the greatest key less than or equal to key , or null if there is no such key |
Exceptions |
java.lang.ClassCastException |
if the specified key cannot be compared with the keys currently in the map |
java.lang.NullPointerException |
if the specified key is null |
forEach
open fun forEach(action: BiConsumer<in K, in V>): Unit
Parameters |
action |
BiConsumer<in K, in V>: The action to be performed for each entry |
Exceptions |
java.lang.NullPointerException |
if the specified action is null |
java.util.ConcurrentModificationException |
if an entry is found to be removed during iteration |
get
open fun get(key: K): V?
Returns the value to which the specified key is mapped, or null
if this map contains no mapping for the key.
More formally, if this map contains a mapping from a key k
to a value v
such that key
compares equal to k
according to the map's ordering, then this method returns v
; otherwise it returns null
. (There can be at most one such mapping.)
Parameters |
key |
K: the key whose associated value is to be returned |
Return |
V? |
the value to which the specified key is mapped, or null if this map contains no mapping for the key |
Exceptions |
java.lang.ClassCastException |
if the specified key cannot be compared with the keys currently in the map |
java.lang.NullPointerException |
if the specified key is null |
get
open fun get(key: K): V?
Returns the value to which the specified key is mapped, or null
if this map contains no mapping for the key.
More formally, if this map contains a mapping from a key k
to a value v
such that key
compares equal to k
according to the map's ordering, then this method returns v
; otherwise it returns null
. (There can be at most one such mapping.)
Parameters |
key |
K: the key whose associated value is to be returned |
Return |
V? |
the value to which the specified key is mapped, or null if this map contains no mapping for the key |
Exceptions |
java.lang.ClassCastException |
if the specified key cannot be compared with the keys currently in the map |
java.lang.NullPointerException |
if the specified key is null |
getOrDefault
open fun getOrDefault(
key: K,
defaultValue: V
): V
Returns the value to which the specified key is mapped, or the given defaultValue if this map contains no mapping for the key.
Parameters |
key |
K: the key |
defaultValue |
V: the value to return if this map contains no mapping for the given key |
Return |
V |
the mapping for the key, if present; else the defaultValue |
Exceptions |
java.lang.ClassCastException |
if the key is of an inappropriate type for this map (java.util.Collection#) |
java.lang.NullPointerException |
if the specified key is null |
headMap
open fun headMap(toKey: K): ConcurrentNavigableMap<K, V>
Parameters |
toKey |
K: high endpoint (exclusive) of the keys in the returned map |
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 |
java.lang.IllegalArgumentException |
if this map itself has a restricted range, and toKey lies outside the bounds of the range |
headMap
open 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 |
java.lang.IllegalArgumentException |
if this map itself has a restricted range, and toKey lies outside the bounds of the range |
higherEntry
open fun higherEntry(key: K): MutableEntry<K, V>?
Returns a key-value mapping associated with the least key strictly greater than the given key, or null
if there is no such key. The returned entry does not support the Entry.setValue
method.
Parameters |
key |
K: the key |
Return |
MutableEntry<K, V>? |
an entry with the least key greater than key , or null if there is no such key |
Exceptions |
java.lang.ClassCastException |
if the specified key cannot be compared with the keys currently in the map |
java.lang.NullPointerException |
if the specified key is null |
higherKey
open fun higherKey(key: K): K?
Parameters |
key |
K: the key |
Return |
K? |
the least key greater than key , or null if there is no such key |
Exceptions |
java.lang.ClassCastException |
if the specified key cannot be compared with the keys currently in the map |
java.lang.NullPointerException |
if the specified key is null |
isEmpty
open fun isEmpty(): Boolean
Returns true
if this map contains no key-value mappings.
Return |
Boolean |
true if this map contains no key-value mappings |
lastEntry
open fun lastEntry(): MutableEntry<K, V>?
Returns a key-value mapping associated with the greatest key in this map, or null
if the map is empty. The returned entry does not support the Entry.setValue
method.
Return |
MutableEntry<K, V>? |
an entry with the greatest key, or null if this map is empty |
lastKey
open fun lastKey(): K
Return |
K |
the last (highest) key currently in this map |
Exceptions |
java.util.NoSuchElementException |
if this map is empty |
lowerEntry
open fun lowerEntry(key: K): MutableEntry<K, V>?
Returns a key-value mapping associated with the greatest key strictly less than the given key, or null
if there is no such key. The returned entry does not support the Entry.setValue
method.
Parameters |
key |
K: the key |
Return |
MutableEntry<K, V>? |
an entry with the greatest key less than key , or null if there is no such key |
Exceptions |
java.lang.ClassCastException |
if the specified key cannot be compared with the keys currently in the map |
java.lang.NullPointerException |
if the specified key is null |
lowerKey
open fun lowerKey(key: K): K?
Parameters |
key |
K: the key |
Return |
K? |
the greatest key less than key , or null if there is no such key |
Exceptions |
java.lang.ClassCastException |
if the specified key cannot be compared with the keys currently in the map |
java.lang.NullPointerException |
if the specified key is null |
merge
open fun merge(
key: K,
value: V,
remappingFunction: BiFunction<in V, in V, out V?>
): V?
If the specified key is not already associated with a value, associates it with the given value. Otherwise, replaces the value with the results of the given remapping function, or removes if null
. The function is NOT guaranteed to be applied once atomically.
Parameters |
key |
K: key with which the specified value is to be associated |
value |
V: the value to use if absent |
remappingFunction |
BiFunction<in V, in V, out V?>: the function to recompute a value if present |
Return |
V? |
the new value associated with the specified key, or null if none |
Exceptions |
java.lang.UnsupportedOperationException |
if the put operation is not supported by this map (java.util.Collection#) |
java.lang.ClassCastException |
if the class of the specified key or value prevents it from being stored in this map (java.util.Collection#) |
java.lang.IllegalArgumentException |
if some property of the specified key or value prevents it from being stored in this map (java.util.Collection#) |
java.lang.NullPointerException |
if the specified key or value is null or the remappingFunction is null |
navigableKeySet
open fun navigableKeySet(): NavigableSet<K>
Return |
NavigableSet<K> |
a navigable set view of the keys in this map |
pollFirstEntry
open fun pollFirstEntry(): MutableEntry<K, V>?
Removes and returns a key-value mapping associated with the least key in this map, or null
if the map is empty. The returned entry does not support the Entry.setValue
method.
Return |
MutableEntry<K, V>? |
the removed first entry of this map, or null if this map is empty |
Exceptions |
java.lang.UnsupportedOperationException |
if this collection implementation does not support this operation |
pollLastEntry
open fun pollLastEntry(): MutableEntry<K, V>?
Removes and returns a key-value mapping associated with the greatest key in this map, or null
if the map is empty. The returned entry does not support the Entry.setValue
method.
Return |
MutableEntry<K, V>? |
the removed last entry of this map, or null if this map is empty |
Exceptions |
java.lang.UnsupportedOperationException |
if this collection implementation does not support this operation |
put
open fun put(
key: K,
value: V
): V?
Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced.
Parameters |
key |
K: key with which the specified value is to be associated |
value |
V: value to be associated with the specified key |
Return |
V? |
the previous value associated with the specified key, or null if there was no mapping for the key |
Exceptions |
java.lang.UnsupportedOperationException |
if the put operation is not supported by this map |
java.lang.ClassCastException |
if the specified key cannot be compared with the keys currently in the map |
java.lang.NullPointerException |
if the specified key or value is null |
java.lang.IllegalArgumentException |
if some property of the specified key or value prevents it from being stored in this map |
putFirst
open fun putFirst(
k: K,
v: 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.
Parameters |
k |
K: the key |
v |
V: the value |
Return |
V? |
the value previously associated with k, or null if none |
Exceptions |
java.lang.UnsupportedOperationException |
always |
putIfAbsent
open fun putIfAbsent(
key: K,
value: V
): V?
If the specified key is not already associated with a value (or is mapped to null
) associates it with the given value and returns null
, else returns the current value.
Parameters |
key |
K: key with which the specified value is to be associated |
value |
V: value to be associated with the specified key |
Return |
V? |
the previous value associated with the specified key, or null if there was no mapping for the key |
Exceptions |
java.lang.UnsupportedOperationException |
if the put operation is not supported by this map |
java.lang.ClassCastException |
if the specified key cannot be compared with the keys currently in the map |
java.lang.NullPointerException |
if the specified key or value is null |
java.lang.IllegalArgumentException |
if some property of the specified key or value prevents it from being stored in this map |
putLast
open fun putLast(
k: K,
v: 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.
Parameters |
k |
K: the key |
v |
V: the value |
Return |
V? |
the value previously associated with k, or null if none |
Exceptions |
java.lang.UnsupportedOperationException |
always |
remove
open fun remove(key: K): V?
Removes the mapping for the specified key from this map if present.
Parameters |
key |
K: key for which mapping should be removed |
Return |
V? |
the previous value associated with the specified key, or null if there was no mapping for the key |
Exceptions |
java.lang.UnsupportedOperationException |
if the remove operation is not supported by this map |
java.lang.ClassCastException |
if the specified key cannot be compared with the keys currently in the map |
java.lang.NullPointerException |
if the specified key is null |
remove
open fun remove(
key: K,
value: V
): Boolean
Removes the entry for the specified key only if it is currently mapped to the specified value.
Parameters |
key |
K: key with which the specified value is associated |
value |
V: value expected to be associated with the specified key |
Return |
Boolean |
true if the value was removed |
Exceptions |
java.lang.UnsupportedOperationException |
if the remove operation is not supported by this map |
java.lang.ClassCastException |
if the specified key cannot be compared with the keys currently in the map |
java.lang.NullPointerException |
if the specified key is null |
remove
open fun remove(key: K): V?
Removes the mapping for the specified key from this map if present.
Parameters |
key |
K: key for which mapping should be removed |
Return |
V? |
the previous value associated with the specified key, or null if there was no mapping for the key |
Exceptions |
java.lang.UnsupportedOperationException |
if the remove operation is not supported by this map |
java.lang.ClassCastException |
if the specified key cannot be compared with the keys currently in the map |
java.lang.NullPointerException |
if the specified key is null |
replace
open fun replace(
key: K,
value: V
): V?
Replaces the entry for the specified key only if it is currently mapped to some value.
Parameters |
key |
K: key with which the specified value is associated |
value |
V: value to be associated with the specified key |
Return |
V? |
the previous value associated with the specified key, or null if there was no mapping for the key |
Exceptions |
java.lang.UnsupportedOperationException |
if the put operation is not supported by this map |
java.lang.ClassCastException |
if the specified key cannot be compared with the keys currently in the map |
java.lang.NullPointerException |
if the specified key or value is null |
java.lang.IllegalArgumentException |
if some property of the specified key or value prevents it from being stored in this map |
replace
open fun replace(
key: K,
oldValue: V,
newValue: V
): Boolean
Replaces the entry for the specified key only if currently mapped to the specified value.
Parameters |
key |
K: key with which the specified value is associated |
oldValue |
V: value expected to be associated with the specified key |
newValue |
V: value to be associated with the specified key |
Return |
Boolean |
true if the value was replaced |
Exceptions |
java.lang.UnsupportedOperationException |
if the put operation is not supported by this map |
java.lang.ClassCastException |
if the specified key cannot be compared with the keys currently in the map |
java.lang.NullPointerException |
if any of the arguments are null |
java.lang.IllegalArgumentException |
if some property of a specified key or value prevents it from being stored in this map |
replaceAll
open fun replaceAll(function: BiFunction<in K, in V, out V>): Unit
Parameters |
function |
BiFunction<in K, in V, out V>: the function to apply to each entry |
Exceptions |
java.lang.UnsupportedOperationException |
if the set operation is not supported by this map's entry set iterator. |
java.lang.ClassCastException |
if the class of a replacement value prevents it from being stored in this map (java.util.Collection#) |
java.lang.NullPointerException |
if the specified function is null, or if a replacement value is null and this map does not permit null values (java.util.Collection#) |
java.lang.IllegalArgumentException |
if some property of a replacement value prevents it from being stored in this map (java.util.Collection#) |
java.util.ConcurrentModificationException |
if an entry is found to be removed during iteration |
subMap
open 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 |
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 |
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
open 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 |
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
open 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 |
java.lang.IllegalArgumentException |
if this map itself has a restricted range, and fromKey lies outside the bounds of the range |
tailMap
open 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 |
java.lang.IllegalArgumentException |
if this map itself has a restricted range, and fromKey lies outside the bounds of the range |
Properties
entries
open val entries: MutableSet<MutableEntry<K, V>>
Returns a Set
view of the mappings contained in this map.
The set's iterator returns the entries in ascending key order. The set's spliterator additionally reports Spliterator.CONCURRENT
, Spliterator.NONNULL
, Spliterator.SORTED
and Spliterator.ORDERED
, with an encounter order that is ascending key 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.
The Map.Entry
elements traversed by the iterator
or spliterator
do not support the setValue
operation.
Return |
MutableSet<MutableEntry<K, V>> |
a set view of the mappings contained in this map, sorted in ascending key order |
keys
open 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's spliterator additionally reports Spliterator.CONCURRENT
, Spliterator.NONNULL
, Spliterator.SORTED
and Spliterator.ORDERED
, with an encounter order that is ascending key order.
The spliterator's comparator is null
if the map's comparator is null
. Otherwise, the spliterator's comparator is the same as or imposes the same total ordering as the map's comparator.
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 |
size
open val size: Int
Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE
elements, returns Integer.MAX_VALUE
.
Return |
Int |
the number of key-value mappings in this map |
values
open val values: MutableCollection<V>
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 collections's spliterator additionally reports Spliterator.CONCURRENT
, Spliterator.NONNULL
and Spliterator.ORDERED
, with an encounter order that is 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. 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.
The view's iterators and spliterators are weakly consistent.
Return |
MutableCollection<V> |
a collection view of the values contained in this map, sorted in ascending key order |