Interface ConcurrentNavigableMap<K,V>
- Type Parameters:
K- the type of keys maintained by this mapV- the type of mapped values
- All Superinterfaces:
ConcurrentMap<K,V>, Map<K, V>, NavigableMap<K, V>, SequencedMap<K, V>, SortedMap<K, V>
- All Known Implementing Classes:
ConcurrentSkipListMap
ConcurrentMap supporting NavigableMap operations,
and recursively so for its navigable sub-maps.
This interface is a member of the Java Collections Framework.
- Since:
- 1.6
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns a reverse orderNavigableSetview of the keys contained in this map.Returns a reverse order view of the mappings contained in this map.Returns a view of the portion of this map whose keys are strictly less thantoKey.Returns a view of the portion of this map whose keys are less than (or equal to, ifinclusiveis true)toKey.keySet()Returns aNavigableSetview of the keys contained in this map.Returns aNavigableSetview of the keys contained in this map.Returns a view of the portion of this map whose keys range fromfromKeytotoKey.Returns a view of the portion of this map whose keys range fromfromKey, inclusive, totoKey, exclusive.Returns a view of the portion of this map whose keys are greater than or equal tofromKey.Returns a view of the portion of this map whose keys are greater than (or equal to, ifinclusiveis true)fromKey.Methods declared in interface ConcurrentMap
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAllModifier and TypeMethodDescriptiondefault VAttempts to compute a mapping for the specified key and its current mapped value, ornullif there is no current mapping (optional operation).default VcomputeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) If the specified key is not already associated with a value (or is mapped tonull), attempts to compute its value using the given mapping function and enters it into this map unlessnull(optional operation).default VcomputeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) 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 (optional operation).default voidforEach(BiConsumer<? super K, ? super V> action) Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.default VgetOrDefault(Object key, V defaultValue) Returns the value to which the specified key is mapped, ordefaultValueif this map contains no mapping for the key.default VIf the specified key is not already associated with a value or is associated with null, associates it with the given non-null value (optional operation).putIfAbsent(K key, V value) If the specified key is not already associated with a value, associates it with the given value.booleanRemoves the entry for a key only if currently mapped to a given value.Replaces the entry for a key only if currently mapped to some value.booleanReplaces the entry for a key only if currently mapped to a given value.default voidreplaceAll(BiFunction<? super K, ? super V, ? extends V> function) 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 (optional operation).Methods declared in interface Map
clear, containsKey, containsValue, equals, get, hashCode, isEmpty, put, putAll, remove, sizeModifier and TypeMethodDescriptionvoidclear()Removes all of the mappings from this map (optional operation).booleancontainsKey(Object key) Returnstrueif this map contains a mapping for the specified key.booleancontainsValue(Object value) Returnstrueif this map maps one or more keys to the specified value.booleanCompares the specified object with this map for equality.Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.inthashCode()Returns the hash code value for this map.booleanisEmpty()Returnstrueif this map contains no key-value mappings.Associates the specified value with the specified key in this map (optional operation).voidCopies all of the mappings from the specified map to this map (optional operation).Removes the mapping for a key from this map if it is present (optional operation).intsize()Returns the number of key-value mappings in this map.Methods declared in interface NavigableMap
ceilingEntry, ceilingKey, firstEntry, floorEntry, floorKey, higherEntry, higherKey, lastEntry, lowerEntry, lowerKey, pollFirstEntry, pollLastEntry, reversedModifier and TypeMethodDescriptionceilingEntry(K key) Returns a key-value mapping associated with the least key greater than or equal to the given key, ornullif there is no such key.ceilingKey(K key) Returns the least key greater than or equal to the given key, ornullif there is no such key.Returns a key-value mapping associated with the least key in this map, ornullif the map is empty.floorEntry(K key) Returns a key-value mapping associated with the greatest key less than or equal to the given key, ornullif there is no such key.Returns the greatest key less than or equal to the given key, ornullif there is no such key.higherEntry(K key) Returns a key-value mapping associated with the least key strictly greater than the given key, ornullif there is no such key.Returns the least key strictly greater than the given key, ornullif there is no such key.Returns a key-value mapping associated with the greatest key in this map, ornullif the map is empty.lowerEntry(K key) Returns a key-value mapping associated with the greatest key strictly less than the given key, ornullif there is no such key.Returns the greatest key strictly less than the given key, ornullif there is no such key.Removes and returns a key-value mapping associated with the least key in this map, ornullif the map is empty (optional operation).Removes and returns a key-value mapping associated with the greatest key in this map, ornullif the map is empty (optional operation).default NavigableMap<K, V> reversed()Returns a reverse-ordered view of this map.Methods declared in interface SequencedMap
sequencedEntrySet, sequencedKeySet, sequencedValuesModifier and TypeMethodDescriptiondefault SequencedSet<Map.Entry<K, V>> Returns aSequencedSetview of this map'sentrySet.default SequencedSet<K> Returns aSequencedSetview of this map'skeySet.default SequencedCollection<V> Returns aSequencedCollectionview of this map'svaluescollection.Methods declared in interface SortedMap
comparator, entrySet, firstKey, lastKey, putFirst, putLast, valuesModifier and TypeMethodDescriptionComparator<? super K> Returns the comparator used to order the keys in this map, ornullif this map uses the natural ordering of its keys.entrySet()Returns aSetview of the mappings contained in this map.firstKey()Returns the first (lowest) key currently in this map.lastKey()Returns the last (highest) key currently in this map.default VThrowsUnsupportedOperationException.default VThrowsUnsupportedOperationException.values()Returns aCollectionview of the values contained in this map.
-
Method Details
-
subMap
Description copied from interface:NavigableMapReturns a view of the portion of this map whose keys range fromfromKeytotoKey. IffromKeyandtoKeyare equal, the returned map is empty unlessfromInclusiveandtoInclusiveare both true. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.The returned map will throw an
IllegalArgumentExceptionon an attempt to insert a key outside of its range, or to construct a submap either of whose endpoints lie outside its range.- Specified by:
subMapin interfaceNavigableMap<K,V> - Parameters:
fromKey- low endpoint of the keys in the returned mapfromInclusive-trueif the low endpoint is to be included in the returned viewtoKey- high endpoint of the keys in the returned maptoInclusive-trueif the high endpoint is to be included in the returned view- Returns:
- a view of the portion of this map whose keys range from
fromKeytotoKey - Throws:
ClassCastException- iffromKeyandtoKeycannot 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 iffromKeyortoKeycannot be compared to keys currently in the map.NullPointerException- iffromKeyortoKeyis null and this map does not permit null keysIllegalArgumentException- iffromKeyis greater thantoKey; or if this map itself has a restricted range, andfromKeyortoKeylies outside the bounds of the range
-
headMap
Description copied from interface:NavigableMapReturns a view of the portion of this map whose keys are less than (or equal to, ifinclusiveis true)toKey. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.The returned map will throw an
IllegalArgumentExceptionon an attempt to insert a key outside its range.- Specified by:
headMapin interfaceNavigableMap<K,V> - Parameters:
toKey- high endpoint of the keys in the returned mapinclusive-trueif the high endpoint is to be included in the returned view- Returns:
- a view of the portion of this map whose keys are less than
(or equal to, if
inclusiveis true)toKey - Throws:
ClassCastException- iftoKeyis not compatible with this map's comparator (or, if the map has no comparator, iftoKeydoes not implementComparable). Implementations may, but are not required to, throw this exception iftoKeycannot be compared to keys currently in the map.NullPointerException- iftoKeyis null and this map does not permit null keysIllegalArgumentException- if this map itself has a restricted range, andtoKeylies outside the bounds of the range
-
tailMap
Description copied from interface:NavigableMapReturns a view of the portion of this map whose keys are greater than (or equal to, ifinclusiveis true)fromKey. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.The returned map will throw an
IllegalArgumentExceptionon an attempt to insert a key outside its range.- Specified by:
tailMapin interfaceNavigableMap<K,V> - Parameters:
fromKey- low endpoint of the keys in the returned mapinclusive-trueif the low endpoint is to be included in the returned view- Returns:
- a view of the portion of this map whose keys are greater than
(or equal to, if
inclusiveis true)fromKey - Throws:
ClassCastException- iffromKeyis not compatible with this map's comparator (or, if the map has no comparator, iffromKeydoes not implementComparable). Implementations may, but are not required to, throw this exception iffromKeycannot be compared to keys currently in the map.NullPointerException- iffromKeyis null and this map does not permit null keysIllegalArgumentException- if this map itself has a restricted range, andfromKeylies outside the bounds of the range
-
subMap
Description copied from interface:NavigableMapReturns a view of the portion of this map whose keys range fromfromKey, inclusive, totoKey, exclusive. (IffromKeyandtoKeyare equal, the returned map is empty.) The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.The returned map will throw an
IllegalArgumentExceptionon an attempt to insert a key outside its range.Equivalent to
subMap(fromKey, true, toKey, false).- Specified by:
subMapin interfaceNavigableMap<K,V> - Specified by:
subMapin interfaceSortedMap<K,V> - Parameters:
fromKey- low endpoint (inclusive) of the keys in the returned maptoKey- high endpoint (exclusive) of the keys in the returned map- Returns:
- a view of the portion of this map whose keys range from
fromKey, inclusive, totoKey, exclusive - Throws:
ClassCastException- iffromKeyandtoKeycannot 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 iffromKeyortoKeycannot be compared to keys currently in the map.NullPointerException- iffromKeyortoKeyis null and this map does not permit null keysIllegalArgumentException- iffromKeyis greater thantoKey; or if this map itself has a restricted range, andfromKeyortoKeylies outside the bounds of the range
-
headMap
Description copied from interface:NavigableMapReturns a view of the portion of this map whose keys are strictly less thantoKey. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.The returned map will throw an
IllegalArgumentExceptionon an attempt to insert a key outside its range.Equivalent to
headMap(toKey, false).- Specified by:
headMapin interfaceNavigableMap<K,V> - Specified by:
headMapin interfaceSortedMap<K,V> - Parameters:
toKey- high endpoint (exclusive) of the keys in the returned map- Returns:
- a view of the portion of this map whose keys are strictly
less than
toKey - Throws:
ClassCastException- iftoKeyis not compatible with this map's comparator (or, if the map has no comparator, iftoKeydoes not implementComparable). Implementations may, but are not required to, throw this exception iftoKeycannot be compared to keys currently in the map.NullPointerException- iftoKeyis null and this map does not permit null keysIllegalArgumentException- if this map itself has a restricted range, andtoKeylies outside the bounds of the range
-
tailMap
Description copied from interface:NavigableMapReturns a view of the portion of this map whose keys are greater than or equal tofromKey. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.The returned map will throw an
IllegalArgumentExceptionon an attempt to insert a key outside its range.Equivalent to
tailMap(fromKey, true).- Specified by:
tailMapin interfaceNavigableMap<K,V> - Specified by:
tailMapin interfaceSortedMap<K,V> - Parameters:
fromKey- low endpoint (inclusive) of the keys in the returned map- Returns:
- a view of the portion of this map whose keys are greater
than or equal to
fromKey - Throws:
ClassCastException- iffromKeyis not compatible with this map's comparator (or, if the map has no comparator, iffromKeydoes not implementComparable). Implementations may, but are not required to, throw this exception iffromKeycannot be compared to keys currently in the map.NullPointerException- iffromKeyis null and this map does not permit null keysIllegalArgumentException- if this map itself has a restricted range, andfromKeylies outside the bounds of the range
-
descendingMap
ConcurrentNavigableMap<K,V> descendingMap()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
Collections.reverseOrder(comparator()). The expressionm.descendingMap().descendingMap()returns a view ofmessentially equivalent tom.- Specified by:
descendingMapin interfaceNavigableMap<K,V> - Returns:
- a reverse order view of this map
-
keySet
NavigableSet<K> keySet()Returns aNavigableSetview 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 theIterator.remove,Set.remove,removeAll,retainAll, andclearoperations. It does not support theaddoraddAlloperations.The view's iterators and spliterators are weakly consistent.
This method is equivalent to method
navigableKeySet. -
descendingKeySet
NavigableSet<K> descendingKeySet()Returns a reverse orderNavigableSetview 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 theIterator.remove,Set.remove,removeAll,retainAll, andclearoperations. It does not support theaddoraddAlloperations.The view's iterators and spliterators are weakly consistent.
- Specified by:
descendingKeySetin interfaceNavigableMap<K,V> - Returns:
- a reverse order navigable set view of the keys in this map
-