Package org.djutils.immutablecollections
Interface ImmutableSortedMap<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> Serializable
- All Known Subinterfaces:
ImmutableNavigableMap<K,
V>
- All Known Implementing Classes:
ImmutableTreeMap
A SortedMap interface without the methods that can change it. The return values of subMap, tailMap and headMap are all
ImmutableSortedMaps.
Copyright (c) 2016-2024 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
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.djutils.immutablecollections.ImmutableMap
ImmutableMap.ImmutableEntry<K,
V> -
Method Summary
Modifier and TypeMethodDescriptionComparator<? super K>
Returns the comparator used to order the keys in this immutable map, ornull
if this immutable map uses the natural ordering of its keys.boolean
Force to redefine equals for the implementations of immutable collection classes.firstKey()
Returns the first (lowest) key currently in this immutable map.int
hashCode()
Force to redefine hashCode for the implementations of immutable collection classes.Returns a view of the portion of this immutable map whose keys are strictly less thantoKey
.keySet()
Return an ImmutableSortedSet view of the keys contained in this immutable map.lastKey()
Returns the last (highest) key currently in this immutable map.static <K,
V> ImmutableSortedMap<K, V> of()
Return an empty ImmutableSortedMap, backed by a TreeMap.static <K,
V> ImmutableSortedMap<K, V> of
(K k1, V v1) Return an ImmutableSortedMap with 1 entry, backed by a TreeMap.static <K,
V> ImmutableSortedMap<K, V> of
(K k1, V v1, K k2, V v2) Return an ImmutableSortedMap with 2 entries, backed by a TreeMap.static <K,
V> ImmutableSortedMap<K, V> of
(K k1, V v1, K k2, V v2, K k3, V v3) Return an ImmutableSortedMap with 3 entries, backed by a TreeMap.static <K,
V> ImmutableSortedMap<K, V> of
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) Return an ImmutableSortedMap with 4 entries, backed by a TreeMap.static <K,
V> ImmutableSortedMap<K, V> of
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) Return an ImmutableSortedMap with 5 entries, backed by a TreeMap.static <K,
V> ImmutableSortedMap<K, V> of
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6) Return an ImmutableSortedMap with 6 entries, backed by a TreeMap.static <K,
V> ImmutableSortedMap<K, V> of
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7) Return an ImmutableSortedMap with 7 entries, backed by a TreeMap.static <K,
V> ImmutableSortedMap<K, V> of
(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8) Return an ImmutableSortedMap with 8 entries, backed by a TreeMap.Returns a view of the portion of this immutable map whose keys range fromfromKey
, inclusive, totoKey
, exclusive.Returns a view of the portion of this immutable map whose keys are greater than or equal tofromKey
.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
-
Method Details
-
toMap
Returns a modifiable copy of this immutable map.- Specified by:
toMap
in interfaceImmutableMap<K,
V> - Returns:
- a modifiable copy of this immutable map.
-
comparator
Comparator<? super K> comparator()Returns the comparator used to order the keys in this immutable map, ornull
if this immutable map uses the natural ordering of its keys.- Returns:
- the comparator used to order the keys in this immutable map, or
null
if this immutable map uses the natural ordering of its keys
-
subMap
Returns a view of the portion of this immutable map whose keys range fromfromKey
, inclusive, totoKey
, exclusive. (IffromKey
andtoKey
are equal, the returned immutable map is empty.)The result of this method is a new, immutable sorted map.
- Parameters:
fromKey
- K; low endpoint (inclusive) of the returned immutable maptoKey
- K; high endpoint (exclusive) of the returned immutable map- Returns:
- a new, immutable sorted map 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 strictly less thantoKey
. The returned immutable map is backed by this immutable map, so changes in the returned immutable map are reflected in this immutable map, and vice-versa. The returned immutable map supports all optional immutable map operations that this immutable map supports.The result of this method is a new, immutable sorted map.
- Parameters:
toKey
- K; high endpoint (exclusive) of the returned immutable map- Returns:
- a view of the portion of this immutable map whose keys are strictly less than
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 tofromKey
. The returned immutable map is backed by this immutable map, so changes in the returned immutable map are reflected in this immutable map, and vice-versa. The returned immutable map supports all optional immutable map operations that this immutable map supports.The result of this method is a new, immutable sorted map.
- Parameters:
fromKey
- K; low endpoint (inclusive) of the returned immutable map- 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
-
firstKey
K firstKey()Returns the first (lowest) key currently in this immutable map.- Returns:
- the first (lowest) key currently in this immutable map
- Throws:
NoSuchElementException
- if this immutable map is empty
-
lastKey
K lastKey()Returns the last (highest) key currently in this immutable map.- Returns:
- the last (highest) key currently in this immutable map
- Throws:
NoSuchElementException
- if this immutable map is empty
-
keySet
ImmutableSortedSet<K> keySet()Return an ImmutableSortedSet view of the keys contained in this immutable map.- Specified by:
keySet
in interfaceImmutableMap<K,
V> - Returns:
- an ImmutableSortedSet view of the keys contained in this immutable map
-
equals
Force to redefine equals for the implementations of immutable collection classes. -
hashCode
int hashCode()Force to redefine hashCode for the implementations of immutable collection classes. -
of
Return an empty ImmutableSortedMap, backed by a TreeMap.- Type Parameters:
K
- the key typeV
- the value type- Returns:
- ImmutableSortedMap<K, V>; an empty ImmutableSortedMap
-
of
Return an ImmutableSortedMap with 1 entry, backed by a TreeMap.- Type Parameters:
K
- the key typeV
- the value type- Parameters:
k1
- K; key 1v1
- V; value 1- Returns:
- ImmutableSortedMap<K, V>; an ImmutableSortedMap with 1 entry, backed by a TreeMap
-
of
Return an ImmutableSortedMap with 2 entries, backed by a TreeMap.- Type Parameters:
K
- the key typeV
- the value type- Parameters:
k1
- K; key 1v1
- V; value 1k2
- K; key 2v2
- V; value 2- Returns:
- ImmutableSortedMap<K, V>; an ImmutableSortedMap with 2 entries, backed by a TreeMap
-
of
Return an ImmutableSortedMap with 3 entries, backed by a TreeMap.- Type Parameters:
K
- the key typeV
- the value type- Parameters:
k1
- K; key 1v1
- V; value 1k2
- K; key 2v2
- V; value 2k3
- K; key 3v3
- V; value 3- Returns:
- ImmutableSortedMap<K, V>; an ImmutableSortedMap with 3 entries, backed by a TreeMap
-
of
Return an ImmutableSortedMap with 4 entries, backed by a TreeMap.- Type Parameters:
K
- the key typeV
- the value type- Parameters:
k1
- K; key 1v1
- V; value 1k2
- K; key 2v2
- V; value 2k3
- K; key 3v3
- V; value 3k4
- K; key 4v4
- V; value 4- Returns:
- ImmutableSortedMap<K, V>; an ImmutableSortedMap with 4 entries, backed by a TreeMap
-
of
static <K,V> ImmutableSortedMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) Return an ImmutableSortedMap with 5 entries, backed by a TreeMap.- Type Parameters:
K
- the key typeV
- the value type- Parameters:
k1
- K; key 1v1
- V; value 1k2
- K; key 2v2
- V; value 2k3
- K; key 3v3
- V; value 3k4
- K; key 4v4
- V; value 4k5
- K; key 5v5
- V; value 5- Returns:
- ImmutableSortedMap<K, V>; an ImmutableSortedMap with 5 entries, backed by a TreeMap
-
of
static <K,V> ImmutableSortedMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6) Return an ImmutableSortedMap with 6 entries, backed by a TreeMap.- Type Parameters:
K
- the key typeV
- the value type- Parameters:
k1
- K; key 1v1
- V; value 1k2
- K; key 2v2
- V; value 2k3
- K; key 3v3
- V; value 3k4
- K; key 4v4
- V; value 4k5
- K; key 5v5
- V; value 5k6
- K; key 6v6
- V; value 6- Returns:
- ImmutableSortedMap<K, V>; an ImmutableSortedMap with 6 entries, backed by a TreeMap
-
of
static <K,V> ImmutableSortedMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7) Return an ImmutableSortedMap with 7 entries, backed by a TreeMap.- Type Parameters:
K
- the key typeV
- the value type- Parameters:
k1
- K; key 1v1
- V; value 1k2
- K; key 2v2
- V; value 2k3
- K; key 3v3
- V; value 3k4
- K; key 4v4
- V; value 4k5
- K; key 5v5
- V; value 5k6
- K; key 6v6
- V; value 6k7
- K; key 7v7
- V; value 7- Returns:
- ImmutableSortedMap<K, V>; an ImmutableSortedMap with 7 entries, backed by a TreeMap
-
of
static <K,V> ImmutableSortedMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8) Return an ImmutableSortedMap with 8 entries, backed by a TreeMap.- Type Parameters:
K
- the key typeV
- the value type- Parameters:
k1
- K; key 1v1
- V; value 1k2
- K; key 2v2
- V; value 2k3
- K; key 3v3
- V; value 3k4
- K; key 4v4
- V; value 4k5
- K; key 5v5
- V; value 5k6
- K; key 6v6
- V; value 6k7
- K; key 7v7
- V; value 7k8
- K; key 8v8
- V; value 8- Returns:
- ImmutableSortedMap<K, V>; an ImmutableSortedMap with 8 entries, backed by a TreeMap
-