Interface ImmutableSortedMap<K,V>

Type Parameters:
K - the key type of content of this Map
V - 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

public interface ImmutableSortedMap<K,V> extends ImmutableMap<K,V>
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 Type
    Method
    Description
    Comparator<? super K>
    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.
    boolean
    Force to redefine equals for the implementations of immutable collection classes.
    Returns the first (lowest) key currently in this immutable map.
    int
    Force to redefine hashCode for the implementations of immutable collection classes.
    headMap(K toKey)
    Returns a view of the portion of this immutable map whose keys are strictly less than toKey.
    Return an ImmutableSortedSet view of the keys contained in this immutable map.
    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.
    subMap(K fromKey, K toKey)
    Returns a view of the portion of this immutable map whose keys range from fromKey, inclusive, to toKey, exclusive.
    tailMap(K fromKey)
    Returns a view of the portion of this immutable map whose keys are greater than or equal to fromKey.
    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

      SortedMap<K,V> toMap()
      Returns a modifiable copy of this immutable map.
      Specified by:
      toMap in interface ImmutableMap<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, or null 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

      ImmutableSortedMap<K,V> subMap(K fromKey, K toKey)
      Returns a view of the portion of this immutable map whose keys range from fromKey, inclusive, to toKey, exclusive. (If fromKey and toKey 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 map
      toKey - 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, to toKey, exclusive
      Throws:
      ClassCastException - if fromKey and toKey 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 if fromKey or toKey cannot be compared to keys currently in the immutable map.
      NullPointerException - if fromKey or toKey is null and this immutable map does not permit null keys
      IllegalArgumentException - if fromKey is greater than toKey; or if this immutable map itself has a restricted range, and fromKey or toKey lies outside the bounds of the range
    • headMap

      ImmutableSortedMap<K,V> headMap(K toKey)
      Returns a view of the portion of this immutable map whose keys are strictly less than toKey. 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 - if toKey is not compatible with this immutable map's comparator (or, if the immutable map has no comparator, if toKey does not implement Comparable). Implementations may, but are not required to, throw this exception if toKey cannot be compared to keys currently in the immutable map.
      NullPointerException - if toKey is null and this immutable map does not permit null keys
      IllegalArgumentException - if this immutable map itself has a restricted range, and toKey lies outside the bounds of the range
    • tailMap

      ImmutableSortedMap<K,V> tailMap(K fromKey)
      Returns a view of the portion of this immutable map whose keys are greater than or equal to fromKey. 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 - if fromKey is not compatible with this immutable map's comparator (or, if the immutable map has no comparator, if fromKey does not implement Comparable). Implementations may, but are not required to, throw this exception if fromKey cannot be compared to keys currently in the immutable map.
      NullPointerException - if fromKey is null and this immutable map does not permit null keys
      IllegalArgumentException - if this immutable map itself has a restricted range, and fromKey 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

      Return an ImmutableSortedSet view of the keys contained in this immutable map.
      Specified by:
      keySet in interface ImmutableMap<K,V>
      Returns:
      an ImmutableSortedSet view of the keys contained in this immutable map
    • equals

      boolean equals(Object obj)
      Force to redefine equals for the implementations of immutable collection classes.
      Specified by:
      equals in interface ImmutableMap<K,V>
      Overrides:
      equals in class Object
      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 interface ImmutableMap<K,V>
      Overrides:
      hashCode in class Object
      Returns:
      the calculated hashCode
    • of

      static <K, V> ImmutableSortedMap<K,V> of()
      Return an empty ImmutableSortedMap, backed by a TreeMap.
      Type Parameters:
      K - the key type
      V - the value type
      Returns:
      ImmutableSortedMap<K, V>; an empty ImmutableSortedMap
    • of

      static <K, V> ImmutableSortedMap<K,V> of(K k1, V v1)
      Return an ImmutableSortedMap with 1 entry, backed by a TreeMap.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      k1 - K; key 1
      v1 - V; value 1
      Returns:
      ImmutableSortedMap<K, V>; an ImmutableSortedMap with 1 entry, backed by a TreeMap
    • of

      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.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      k1 - K; key 1
      v1 - V; value 1
      k2 - K; key 2
      v2 - V; value 2
      Returns:
      ImmutableSortedMap<K, V>; an ImmutableSortedMap with 2 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)
      Return an ImmutableSortedMap with 3 entries, backed by a TreeMap.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      k1 - K; key 1
      v1 - V; value 1
      k2 - K; key 2
      v2 - V; value 2
      k3 - K; key 3
      v3 - V; value 3
      Returns:
      ImmutableSortedMap<K, V>; an ImmutableSortedMap with 3 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)
      Return an ImmutableSortedMap with 4 entries, backed by a TreeMap.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      k1 - K; key 1
      v1 - V; value 1
      k2 - K; key 2
      v2 - V; value 2
      k3 - K; key 3
      v3 - V; value 3
      k4 - K; key 4
      v4 - 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 type
      V - the value type
      Parameters:
      k1 - K; key 1
      v1 - V; value 1
      k2 - K; key 2
      v2 - V; value 2
      k3 - K; key 3
      v3 - V; value 3
      k4 - K; key 4
      v4 - V; value 4
      k5 - K; key 5
      v5 - 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 type
      V - the value type
      Parameters:
      k1 - K; key 1
      v1 - V; value 1
      k2 - K; key 2
      v2 - V; value 2
      k3 - K; key 3
      v3 - V; value 3
      k4 - K; key 4
      v4 - V; value 4
      k5 - K; key 5
      v5 - V; value 5
      k6 - K; key 6
      v6 - 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 type
      V - the value type
      Parameters:
      k1 - K; key 1
      v1 - V; value 1
      k2 - K; key 2
      v2 - V; value 2
      k3 - K; key 3
      v3 - V; value 3
      k4 - K; key 4
      v4 - V; value 4
      k5 - K; key 5
      v5 - V; value 5
      k6 - K; key 6
      v6 - V; value 6
      k7 - K; key 7
      v7 - 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 type
      V - the value type
      Parameters:
      k1 - K; key 1
      v1 - V; value 1
      k2 - K; key 2
      v2 - V; value 2
      k3 - K; key 3
      v3 - V; value 3
      k4 - K; key 4
      v4 - V; value 4
      k5 - K; key 5
      v5 - V; value 5
      k6 - K; key 6
      v6 - V; value 6
      k7 - K; key 7
      v7 - V; value 7
      k8 - K; key 8
      v8 - V; value 8
      Returns:
      ImmutableSortedMap<K, V>; an ImmutableSortedMap with 8 entries, backed by a TreeMap