- All Implemented Interfaces:
Serializable,Map<K,,V> NavigableMap<K,,V> SortedMap<K,V>
- See Also:
-
Nested Class Summary
Nested classes/interfaces declared in class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
Fields declared in class java.util.TreeMapAbstractMap
keySet, values -
Method Summary
Modifier 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.Comparator<? super K>Returns the comparator used to order the keys in this map, ornullif this map uses the natural ordering of its keys.Attempts to compute a mapping for the specified key and its current mapped value (ornullif there is no current mapping).computeIfAbsent(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.computeIfPresent(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.final booleancontainsKey(Object key) Returnstrueif this map contains a mapping for the specified key.Returns a reverse orderNavigableSetview of the keys contained in this map.Returns a reverse order view of the mappings contained in this map.entrySet()Returns aSetview of the mappings contained in this map.Returns a key-value mapping associated with the least key in this map, ornullif the map is empty.final KfirstKey()Returns the first (lowest) key currently in this map.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.final VReturns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.getCeilingEntry(K key) getFloorEntry(K key) getLowerEntry(K key) 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.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.final KReturns the least key strictly greater than the given key, ornullif there is no such key.booleanisEmpty()Returnstrueif this map contains no key-value mappings.keySet()Returns aSetview of the keys contained in this map.Returns a key-value mapping associated with the greatest key in this map, ornullif the map is empty.final KlastKey()Returns the last (highest) key currently in this map.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.If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value.final NavigableSet<K>Returns aNavigableSetview of the keys contained in this map.Removes and returns a key-value mapping associated with the least key in this map, ornullif the map is empty.Removes and returns a key-value mapping associated with the greatest key in this map, ornullif the map is empty.final VAssociates the specified value with the specified key in this map (optional operation).putIfAbsent(K key, V value) If the specified key is not already associated with a value (or is mapped tonull) associates it with the given value and returnsnull, else returns the current value.final VRemoves 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.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 class java.util.AbstractMap
clear, clone, containsValue, equals, hashCode, putAll, toString, valuesMethods declared in interface java.util.Map
clear, containsValue, equals, forEach, getOrDefault, hashCode, putAll, remove, replace, replace, replaceAll
-
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
-
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
-
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
-
descendingMap
Description copied from interface:NavigableMapReturns 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. If either map is modified while an iteration over a collection view of either map is in progress (except through the iterator's ownremoveoperation), the results of the iteration are undefined.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
-
comparator
Description copied from interface:SortedMapReturns the comparator used to order the keys in this map, ornullif this map uses the natural ordering of its keys.- Specified by:
comparatorin interfaceSortedMap<K,V> - Returns:
- the comparator used to order the keys in this map,
or
nullif this map uses the natural ordering of its keys
-
entrySet
Description copied from interface:SortedMapReturns aSetview 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 ownremoveoperation, or through thesetValueoperation 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 theIterator.remove,Set.remove,removeAll,retainAllandclearoperations. It does not support theaddoraddAlloperations. -
containsKey
Description copied from class:AbstractMapReturnstrueif this map contains a mapping for the specified key. More formally, returnstrueif and only if this map contains a mapping for a keyksuch thatObjects.equals(key, k). (There can be at most one such mapping.)- Specified by:
containsKeyin interfaceMap<K,V> - Overrides:
containsKeyin classAbstractMap<K,V> - Parameters:
key- key whose presence in this map is to be tested- Returns:
trueif this map contains a mapping for the specified key
-
isEmpty
public boolean isEmpty()Description copied from class:AbstractMapReturnstrueif this map contains no key-value mappings.- Specified by:
isEmptyin interfaceMap<K,V> - Overrides:
isEmptyin classAbstractMap<K,V> - Returns:
trueif this map contains no key-value mappings
-
size
public int size()Description copied from class:AbstractMapReturns the number of key-value mappings in this map. If the map contains more thanInteger.MAX_VALUEelements, returnsInteger.MAX_VALUE.- Specified by:
sizein interfaceMap<K,V> - Overrides:
sizein classAbstractMap<K,V> - Returns:
- the number of key-value mappings in this map
-
put
Description copied from class:AbstractMapAssociates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A mapmis said to contain a mapping for a keykif and only ifm.containsKey(k)would returntrue.)- Specified by:
putin interfaceMap<K,V> - Overrides:
putin classAbstractMap<K,V> - Parameters:
key- key with which the specified value is to be associatedvalue- value to be associated with the specified key- Returns:
- the previous value associated with
key, ornullif there was no mapping forkey. (Anullreturn can also indicate that the map previously associatednullwithkey, if the implementation supportsnullvalues.)
-
putIfAbsent
Description copied from interface:MapIf the specified key is not already associated with a value (or is mapped tonull) associates it with the given value and returnsnull, else returns the current value.- Specified by:
putIfAbsentin interfaceMap<K,V> - Parameters:
key- key with which the specified value is to be associatedvalue- value to be associated with the specified key- Returns:
- the previous value associated with the specified key, or
nullif there was no mapping for the key. (Anullreturn can also indicate that the map previously associatednullwith the key, if the implementation supports null values.)
-
merge
Description copied from interface:MapIf 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 isnull. This method may be of use when combining multiple mapped values for a key. For example, to either create or append aString msgto a value mapping:map.merge(key, msg, String::concat)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.
- Specified by:
mergein interfaceMap<K,V> - Parameters:
key- key with which the resulting value is to be associatedvalue- the non-null value to be merged with the existing value associated with the key or, if no existing value or a null value is associated with the key, to be associated with the keyremappingFunction- the remapping function to recompute a value if present- Returns:
- the new value associated with the specified key, or null if no value is associated with the key
-
computeIfAbsent
Description copied from interface:MapIf 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.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:map.computeIfAbsent(key, k -> new Value(f(k)));Or to implement a multi-value map,
Map<K,Collection<V>>, supporting multiple values per key:map.computeIfAbsent(key, k -> new HashSet<V>()).add(v);The mapping function should not modify this map during computation.
- Specified by:
computeIfAbsentin interfaceMap<K,V> - Parameters:
key- key with which the specified value is to be associatedmappingFunction- the mapping function to compute a value- Returns:
- the current (existing or computed) value associated with the specified key, or null if the computed value is null
-
compute
Description copied from interface:MapAttempts to compute a mapping for the specified key and its current mapped value (ornullif there is no current mapping). For example, to either create or append aStringmsg to a value mapping:
(Methodmap.compute(key, (k, v) -> (v == null) ? msg : v.concat(msg))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.
-
computeIfPresent
Description copied from interface:MapIf 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.
- Specified by:
computeIfPresentin interfaceMap<K,V> - Parameters:
key- key with which the specified value is to be associatedremappingFunction- the remapping function to compute a value- Returns:
- the new value associated with the specified key, or null if none
-
get
Description copied from class:AbstractMapReturns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.More formally, if this map contains a mapping from a key
kto a valuevsuch thatObjects.equals(key, k), then this method returnsv; otherwise it returnsnull. (There can be at most one such mapping.)If this map permits null values, then a return value of
nulldoes not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key tonull. ThecontainsKeyoperation may be used to distinguish these two cases.- Specified by:
getin interfaceMap<K,V> - Overrides:
getin classAbstractMap<K,V> - Parameters:
key- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or
nullif this map contains no mapping for the key
-
remove
Description copied from class:AbstractMapRemoves the mapping for a key from this map if it is present (optional operation). More formally, if this map contains a mapping from keykto valuevsuch thatObjects.equals(key, k), that mapping is removed. (The map can contain at most one such mapping.)Returns the value to which this map previously associated the key, or
nullif the map contained no mapping for the key.If this map permits null values, then a return value of
nulldoes not necessarily indicate that the map contained no mapping for the key; it's also possible that the map explicitly mapped the key tonull.The map will not contain a mapping for the specified key once the call returns.
- Specified by:
removein interfaceMap<K,V> - Overrides:
removein classAbstractMap<K,V> - Parameters:
key- key whose mapping is to be removed from the map- Returns:
- the previous value associated with
key, ornullif there was no mapping forkey.
-
firstEntry
Description copied from interface:NavigableMapReturns a key-value mapping associated with the least key in this map, ornullif the map is empty.- Specified by:
firstEntryin interfaceNavigableMap<K,V> - Returns:
- an entry with the least key,
or
nullif this map is empty
-
lastEntry
Description copied from interface:NavigableMapReturns a key-value mapping associated with the greatest key in this map, ornullif the map is empty.- Specified by:
lastEntryin interfaceNavigableMap<K,V> - Returns:
- an entry with the greatest key,
or
nullif this map is empty
-
pollFirstEntry
Description copied from interface:NavigableMapRemoves and returns a key-value mapping associated with the least key in this map, ornullif the map is empty.- Specified by:
pollFirstEntryin interfaceNavigableMap<K,V> - Returns:
- the removed first entry of this map,
or
nullif this map is empty
-
pollLastEntry
Description copied from interface:NavigableMapRemoves and returns a key-value mapping associated with the greatest key in this map, ornullif the map is empty.- Specified by:
pollLastEntryin interfaceNavigableMap<K,V> - Returns:
- the removed last entry of this map,
or
nullif this map is empty
-
higherEntry
Description copied from interface:NavigableMapReturns a key-value mapping associated with the least key strictly greater than the given key, ornullif there is no such key.- Specified by:
higherEntryin interfaceNavigableMap<K,V> - Parameters:
key- the key- Returns:
- an entry with the least key greater than
key, ornullif there is no such key
-
lowerEntry
Description copied from interface:NavigableMapReturns a key-value mapping associated with the greatest key strictly less than the given key, ornullif there is no such key.- Specified by:
lowerEntryin interfaceNavigableMap<K,V> - Parameters:
key- the key- Returns:
- an entry with the greatest key less than
key, ornullif there is no such key
-
ceilingEntry
Description copied from interface:NavigableMapReturns a key-value mapping associated with the least key greater than or equal to the given key, ornullif there is no such key.- Specified by:
ceilingEntryin interfaceNavigableMap<K,V> - Parameters:
key- the key- Returns:
- an entry with the least key greater than or equal to
key, ornullif there is no such key
-
floorEntry
Description copied from interface:NavigableMapReturns a key-value mapping associated with the greatest key less than or equal to the given key, ornullif there is no such key.- Specified by:
floorEntryin interfaceNavigableMap<K,V> - Parameters:
key- the key- Returns:
- an entry with the greatest key less than or equal to
key, ornullif there is no such key
-
firstKey
Description copied from interface:SortedMapReturns the first (lowest) key currently in this map. -
lastKey
Description copied from interface:SortedMapReturns the last (highest) key currently in this map. -
higherKey
Description copied from interface:NavigableMapReturns the least key strictly greater than the given key, ornullif there is no such key.- Specified by:
higherKeyin interfaceNavigableMap<K,V> - Parameters:
key- the key- Returns:
- the least key greater than
key, ornullif there is no such key
-
lowerKey
Description copied from interface:NavigableMapReturns the greatest key strictly less than the given key, ornullif there is no such key.- Specified by:
lowerKeyin interfaceNavigableMap<K,V> - Parameters:
key- the key- Returns:
- the greatest key less than
key, ornullif there is no such key
-
ceilingKey
Description copied from interface:NavigableMapReturns the least key greater than or equal to the given key, ornullif there is no such key.- Specified by:
ceilingKeyin interfaceNavigableMap<K,V> - Parameters:
key- the key- Returns:
- the least key greater than or equal to
key, ornullif there is no such key
-
floorKey
Description copied from interface:NavigableMapReturns the greatest key less than or equal to the given key, ornullif there is no such key.- Specified by:
floorKeyin interfaceNavigableMap<K,V> - Parameters:
key- the key- Returns:
- the greatest key less than or equal to
key, ornullif there is no such key
-
keySet
Description copied from class:AbstractMapReturns aSetview of the keys contained in this map. 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 ownremoveoperation), the results of the iteration are undefined. 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. -
descendingKeySet
Description copied from interface:NavigableMapReturns 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. If the map is modified while an iteration over the set is in progress (except through the iterator's ownremoveoperation), the results of the iteration are undefined. 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.- Specified by:
descendingKeySetin interfaceNavigableMap<K,V> - Returns:
- a reverse order navigable set view of the keys in this map
-
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
-
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
-
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
-
getFloorEntry
-
findEndNode
-
getLowerEntry
-
getCeilingEntry
-