Package org.djutils.immutablecollections
Interface ImmutableNavigableMap<K,V>
- Type Parameters:
K
- the key type of content of this MapV
- the value type of content of this Map
- All Superinterfaces:
ImmutableMap<K,V>
,ImmutableSortedMap<K,V>
,Serializable
- All Known Implementing Classes:
ImmutableTreeMap
public interface ImmutableNavigableMap<K,V> extends ImmutableSortedMap<K,V>
A
ImmutableSortedMap
extended with navigation methods reporting closest matches for given search targets. Methods
lowerKey
, floorKey
, ceilingKey
, and higherKey
return keys respectively less than, less than
or equal, greater than or equal, and greater than a given key, returning null
if there is no such key. All methods
from java.util.NavigableMap that can change the map have been left out.
Copyright (c) 2016-2020 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html.
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.djutils.immutablecollections.ImmutableMap
ImmutableMap.ImmutableEntry<K,V>
-
Method Summary
Modifier and Type Method Description K
ceilingKey(K e)
Returns the least key in this immutable map greater than or equal to the given key, ornull
if there is no such key.ImmutableNavigableMap<K,V>
descendingMap()
Returns a reverse order view of the keys contained in this immutable map.boolean
equals(Object obj)
Force to redefine equals for the implementations of immutable collection classes.K
floorKey(K e)
Returns the greatest key in this immutable map less than or equal to the given key, ornull
if there is no such key.int
hashCode()
Force to redefine hashCode for the implementations of immutable collection classes.ImmutableNavigableMap<K,V>
headMap(K toKey, boolean inclusive)
Returns a view of the portion of this immutable map whose keys are less than (or equal to, ifinclusive
is true)toKey
.K
higherKey(K e)
Returns the least key in this immutable map strictly greater than the given key, ornull
if there is no such key.ImmutableSortedSet<K>
keySet()
Returns aImmutableSortedSet
view of the keys contained in this map.K
lowerKey(K e)
Returns the greatest key in this immutable map strictly less than the given key, ornull
if there is no such key.ImmutableNavigableMap<K,V>
subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)
Returns a view of the portion of this immutable map whose keys range fromfromKey
totoKey
.ImmutableNavigableMap<K,V>
tailMap(K fromKey, boolean inclusive)
Returns a view of the portion of this immutable map whose keys are greater than (or equal to, ifinclusive
is true)fromKey
.NavigableMap<K,V>
toMap()
Returns a modifiable copy of this immutable map.Methods inherited from interface org.djutils.immutablecollections.ImmutableMap
containsKey, containsValue, entrySet, forEach, get, getOrDefault, isCopy, isEmpty, isWrap, size, toString, values
Methods inherited from interface org.djutils.immutablecollections.ImmutableSortedMap
comparator, firstKey, headMap, lastKey, subMap, tailMap
-
Method Details
-
toMap
NavigableMap<K,V> toMap()Returns a modifiable copy of this immutable map.- Specified by:
toMap
in interfaceImmutableMap<K,V>
- Specified by:
toMap
in interfaceImmutableSortedMap<K,V>
- Returns:
- a modifiable copy of this immutable map.
-
keySet
ImmutableSortedSet<K> keySet()Returns aImmutableSortedSet
view of the keys contained in this map.- Specified by:
keySet
in interfaceImmutableMap<K,V>
- Specified by:
keySet
in interfaceImmutableSortedMap<K,V>
- Returns:
- an immutable sorted set of the keys contained in this map
-
lowerKey
Returns the greatest key in this immutable map strictly less than the given key, ornull
if there is no such key.- Parameters:
e
- K; the value to match- Returns:
- the greatest key less than
e
, ornull
if there is no such key - Throws:
ClassCastException
- if the specified key cannot be compared with the keys currently in the immutable mapNullPointerException
- if the specified key is null and this immutable map does not permit null keys
-
floorKey
Returns the greatest key in this immutable map less than or equal to the given key, ornull
if there is no such key.- Parameters:
e
- K; the value to match- Returns:
- the greatest key less than or equal to
e
, ornull
if there is no such key - Throws:
ClassCastException
- if the specified key cannot be compared with the keys currently in the immutable mapNullPointerException
- if the specified key is null and this immutable map does not permit null keys
-
ceilingKey
Returns the least key in this immutable map greater than or equal to the given key, ornull
if there is no such key.- Parameters:
e
- K; the value to match- Returns:
- the least key greater than or equal to
e
, ornull
if there is no such key - Throws:
ClassCastException
- if the specified key cannot be compared with the keys currently in the immutable mapNullPointerException
- if the specified key is null and this immutable map does not permit null keys
-
higherKey
Returns the least key in this immutable map strictly greater than the given key, ornull
if there is no such key.- Parameters:
e
- K; the value to match- Returns:
- the least key greater than
e
, ornull
if there is no such key - Throws:
ClassCastException
- if the specified key cannot be compared with the keys currently in the immutable mapNullPointerException
- if the specified key is null and this immutable map does not permit null keys
-
descendingMap
ImmutableNavigableMap<K,V> descendingMap()Returns a reverse order view of the keys contained in this immutable map.The returned immutable map has an ordering equivalent to
. The expressionCollections.reverseOrder
(comparator())s.descendingMap().descendingMap()
returns a view ofs
essentially equivalent tos
.- Returns:
- a reverse order view of this immutable map
-
subMap
Returns a view of the portion of this immutable map whose keys range fromfromKey
totoKey
. IffromKey
andtoKey
are equal, the returned immutable map is empty unlessfromInclusive
andtoInclusive
are both true.- Parameters:
fromKey
- K; low endpoint of the returned immutable mapfromInclusive
- boolean;true
if the low endpoint is to be included in the returned viewtoKey
- K; high endpoint of the returned immutable maptoInclusive
- boolean;true
if the high endpoint is to be included in the returned view- Returns:
- a view of the portion of this immutable map whose keys range from
fromKey
, inclusive, totoKey
, exclusive - Throws:
ClassCastException
- iffromKey
andtoKey
cannot be compared to one another using this immutable map's comparator (or, if the immutable map has no comparator, using natural ordering). Implementations may, but are not required to, throw this exception iffromKey
ortoKey
cannot be compared to keys currently in the immutable map.NullPointerException
- iffromKey
ortoKey
is null and this immutable map does not permit null keysIllegalArgumentException
- iffromKey
is greater thantoKey
; or if this immutable map itself has a restricted range, andfromKey
ortoKey
lies outside the bounds of the range.
-
headMap
Returns a view of the portion of this immutable map whose keys are less than (or equal to, ifinclusive
is true)toKey
.- Parameters:
toKey
- K; high endpoint of the returned immutable mapinclusive
- boolean;true
if the high endpoint is to be included in the returned view- Returns:
- a view of the portion of this immutable map whose keys are less than (or equal to, if
inclusive
is true)toKey
- Throws:
ClassCastException
- iftoKey
is not compatible with this immutable map's comparator (or, if the immutable map has no comparator, iftoKey
does not implementComparable
). Implementations may, but are not required to, throw this exception iftoKey
cannot be compared to keys currently in the immutable map.NullPointerException
- iftoKey
is null and this immutable map does not permit null keysIllegalArgumentException
- if this immutable map itself has a restricted range, andtoKey
lies outside the bounds of the range
-
tailMap
Returns a view of the portion of this immutable map whose keys are greater than (or equal to, ifinclusive
is true)fromKey
.- Parameters:
fromKey
- K; low endpoint of the returned immutable mapinclusive
- boolean;true
if the low endpoint is to be included in the returned view- Returns:
- a view of the portion of this immutable map whose keys are greater than or equal to
fromKey
- Throws:
ClassCastException
- iffromKey
is not compatible with this immutable map's comparator (or, if the immutable map has no comparator, iffromKey
does not implementComparable
). Implementations may, but are not required to, throw this exception iffromKey
cannot be compared to keys currently in the immutable map.NullPointerException
- iffromKey
is null and this immutable map does not permit null keysIllegalArgumentException
- if this immutable map itself has a restricted range, andfromKey
lies outside the bounds of the range
-
equals
Force to redefine equals for the implementations of immutable collection classes.- Specified by:
equals
in interfaceImmutableMap<K,V>
- Specified by:
equals
in interfaceImmutableSortedMap<K,V>
- Overrides:
equals
in classObject
- Parameters:
obj
- Object; the object to compare this collection with- Returns:
- whether the objects are equal
-
hashCode
int hashCode()Force to redefine hashCode for the implementations of immutable collection classes.- Specified by:
hashCode
in interfaceImmutableMap<K,V>
- Specified by:
hashCode
in interfaceImmutableSortedMap<K,V>
- Overrides:
hashCode
in classObject
- Returns:
- the calculated hashCode
-