Package org.djutils.immutablecollections
Class ImmutableTreeMap<K,V>
- java.lang.Object
-
- org.djutils.immutablecollections.ImmutableAbstractMap<K,V>
-
- org.djutils.immutablecollections.ImmutableTreeMap<K,V>
-
- Type Parameters:
K
- the key type of content of this MapV
- the value type of content of this Map
- All Implemented Interfaces:
Serializable
,ImmutableMap<K,V>
,ImmutableNavigableMap<K,V>
,ImmutableSortedMap<K,V>
public class ImmutableTreeMap<K,V> extends ImmutableAbstractMap<K,V> implements ImmutableNavigableMap<K,V>
An immutable wrapper for a TreeMap.Copyright (c) 2016-2021 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
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.djutils.immutablecollections.ImmutableMap
ImmutableMap.ImmutableEntry<K,V>
-
-
Field Summary
-
Fields inherited from class org.djutils.immutablecollections.ImmutableAbstractMap
cachedValues, copyOrWrap
-
-
Constructor Summary
Constructors Constructor Description ImmutableTreeMap(Map<K,V> sortedMap)
ImmutableTreeMap(NavigableMap<K,V> map, Immutable copyOrWrap)
ImmutableTreeMap(ImmutableAbstractMap<K,V> immutableMap)
ImmutableTreeMap(ImmutableTreeMap<K,V> immutableTreeMap, Immutable copyOrWrap)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description K
ceilingKey(K key)
Returns the least key in this immutable map greater than or equal to the given key, ornull
if there is no such key.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.ImmutableNavigableMap<K,V>
descendingMap()
Returns a reverse order view of the keys contained in this immutable map.ImmutableSortedSet<ImmutableMap.ImmutableEntry<K,V>>
entrySet()
Returns aSet
view of the entries contained in this map.K
firstKey()
Returns the first (lowest) key currently in this immutable map.K
floorKey(K key)
Returns the greatest key in this immutable map less than or equal to the given key, ornull
if there is no such key.protected NavigableMap<K,V>
getUnderlyingMap()
Return the raw underlying map.ImmutableSortedMap<K,V>
headMap(K toKey)
Returns a view of the portion of this immutable map whose keys are strictly less thantoKey
.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 key)
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
lastKey()
Returns the last (highest) key currently in this immutable map.K
lowerKey(K key)
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
.ImmutableSortedMap<K,V>
subMap(K fromKey, K toKey)
Returns a view of the portion of this immutable map whose keys range fromfromKey
, inclusive, totoKey
, exclusive.ImmutableSortedMap<K,V>
tailMap(K fromKey)
Returns a view of the portion of this immutable map whose keys are greater than or equal tofromKey
.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.String
toString()
Force to redefine toString.ImmutableSortedSet<V>
values()
Returns aImmutableCollection
view of the values contained in this map.-
Methods inherited from class org.djutils.immutablecollections.ImmutableAbstractMap
containsKey, containsValue, equals, get, hashCode, isEmpty, isWrap, size
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.djutils.immutablecollections.ImmutableMap
containsKey, containsValue, forEach, get, getOrDefault, isCopy, isEmpty, isWrap, size
-
Methods inherited from interface org.djutils.immutablecollections.ImmutableNavigableMap
equals, hashCode
-
-
-
-
Constructor Detail
-
ImmutableTreeMap
public ImmutableTreeMap(Map<K,V> sortedMap)
- Parameters:
sortedMap
- Map<K,V>; the map to use for the immutable map.
-
ImmutableTreeMap
public ImmutableTreeMap(NavigableMap<K,V> map, Immutable copyOrWrap)
- Parameters:
map
- NavigableMap<K,V>; the map to use for the immutable map.copyOrWrap
- COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original collection
-
ImmutableTreeMap
public ImmutableTreeMap(ImmutableAbstractMap<K,V> immutableMap)
- Parameters:
immutableMap
- ImmutableAbstractMap<K,V>; the map to use for the immutable map.
-
ImmutableTreeMap
public ImmutableTreeMap(ImmutableTreeMap<K,V> immutableTreeMap, Immutable copyOrWrap)
- Parameters:
immutableTreeMap
- ImmutableTreeMap<K,V>; the map to use for the immutable map.copyOrWrap
- COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original collection
-
-
Method Detail
-
getUnderlyingMap
protected final NavigableMap<K,V> getUnderlyingMap()
Return the raw underlying map.- Overrides:
getUnderlyingMap
in classImmutableAbstractMap<K,V>
- Returns:
- Map<K, V>; the raw underlying map
-
toMap
public final NavigableMap<K,V> toMap()
Returns a modifiable copy of this immutable map.- Specified by:
toMap
in interfaceImmutableMap<K,V>
- Specified by:
toMap
in interfaceImmutableNavigableMap<K,V>
- Specified by:
toMap
in interfaceImmutableSortedMap<K,V>
- Returns:
- a modifiable copy of this immutable map.
-
keySet
public final ImmutableSortedSet<K> keySet()
Returns aImmutableSortedSet
view of the keys contained in this map.- Specified by:
keySet
in interfaceImmutableMap<K,V>
- Specified by:
keySet
in interfaceImmutableNavigableMap<K,V>
- Specified by:
keySet
in interfaceImmutableSortedMap<K,V>
- Returns:
- an immutable sorted set of the keys contained in this map
-
entrySet
public ImmutableSortedSet<ImmutableMap.ImmutableEntry<K,V>> entrySet()
Returns aSet
view of the entries contained in this map.- Specified by:
entrySet
in interfaceImmutableMap<K,V>
- Returns:
- an immutable set of the entries contained in this map
-
values
public ImmutableSortedSet<V> values()
Returns aImmutableCollection
view of the values contained in this map.- Specified by:
values
in interfaceImmutableMap<K,V>
- Overrides:
values
in classImmutableAbstractMap<K,V>
- Returns:
- an immutable collection view of the values contained in this map
-
comparator
public final 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.- Specified by:
comparator
in interfaceImmutableSortedMap<K,V>
- 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
public final ImmutableSortedMap<K,V> subMap(K fromKey, K toKey)
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.
- Specified by:
subMap
in interfaceImmutableSortedMap<K,V>
- 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
-
headMap
public final ImmutableSortedMap<K,V> headMap(K toKey)
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.
- Specified by:
headMap
in interfaceImmutableSortedMap<K,V>
- 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
-
tailMap
public final ImmutableSortedMap<K,V> tailMap(K fromKey)
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.
- Specified by:
tailMap
in interfaceImmutableSortedMap<K,V>
- 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
-
firstKey
public final K firstKey()
Returns the first (lowest) key currently in this immutable map.- Specified by:
firstKey
in interfaceImmutableSortedMap<K,V>
- Returns:
- the first (lowest) key currently in this immutable map
-
lastKey
public final K lastKey()
Returns the last (highest) key currently in this immutable map.- Specified by:
lastKey
in interfaceImmutableSortedMap<K,V>
- Returns:
- the last (highest) key currently in this immutable map
-
lowerKey
public final K lowerKey(K key)
Returns the greatest key in this immutable map strictly less than the given key, ornull
if there is no such key.- Specified by:
lowerKey
in interfaceImmutableNavigableMap<K,V>
- Parameters:
key
- K; the value to match- Returns:
- the greatest key less than
e
, ornull
if there is no such key
-
floorKey
public final K floorKey(K key)
Returns the greatest key in this immutable map less than or equal to the given key, ornull
if there is no such key.- Specified by:
floorKey
in interfaceImmutableNavigableMap<K,V>
- Parameters:
key
- K; the value to match- Returns:
- the greatest key less than or equal to
e
, ornull
if there is no such key
-
ceilingKey
public final K ceilingKey(K key)
Returns the least key in this immutable map greater than or equal to the given key, ornull
if there is no such key.- Specified by:
ceilingKey
in interfaceImmutableNavigableMap<K,V>
- Parameters:
key
- K; the value to match- Returns:
- the least key greater than or equal to
e
, ornull
if there is no such key
-
higherKey
public final K higherKey(K key)
Returns the least key in this immutable map strictly greater than the given key, ornull
if there is no such key.- Specified by:
higherKey
in interfaceImmutableNavigableMap<K,V>
- Parameters:
key
- K; the value to match- Returns:
- the least key greater than
e
, ornull
if there is no such key
-
descendingMap
public final 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
.- Specified by:
descendingMap
in interfaceImmutableNavigableMap<K,V>
- Returns:
- a reverse order view of this immutable map
-
subMap
public final 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
. IffromKey
andtoKey
are equal, the returned immutable map is empty unlessfromInclusive
andtoInclusive
are both true.- Specified by:
subMap
in interfaceImmutableNavigableMap<K,V>
- 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
-
headMap
public final 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
.- Specified by:
headMap
in interfaceImmutableNavigableMap<K,V>
- 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
-
tailMap
public final 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
.- Specified by:
tailMap
in interfaceImmutableNavigableMap<K,V>
- 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
-
-