Interface OrderedMap<K,V>

Type Parameters:
K - key type
V - value type
All Superinterfaces:
Map<K,V>, SequencedMap<K,V>

public sealed interface OrderedMap<K,V> extends SequencedMap<K,V>
A Map with consistent order of entries. All static factory methods produce unmodifiable maps.
  • Method Details

    • keys

      List<K> keys()
      A List containing the keys of this OrderedMap.

      Because neither Map nor Set equality depends on order, code needing to verify whether an OrderedMap contains the same mappings in the same order should also check for equality of the keys list.

      This method may also be more efficient than calling Map.keySet().

      Returns:
      map keys as list
    • reversed

      OrderedMap<K,V> reversed()
      Specified by:
      reversed in interface SequencedMap<K,V>
    • equals

      boolean equals(Object obj)
      Compares the provided object with this map for equality in accordance with the specification of Map.equals(java.lang.Object).

      Because Map equality does not depends on order, code needing to verify whether an OrderedMap contains the same mappings in the same order should also check for equality of the keys() list.

      Specified by:
      equals in interface Map<K,V>
      Overrides:
      equals in class Object
      Parameters:
      obj - object to compare
      Returns:
      true if the object is a map containing the same mappings, not necessarily in the same order
    • of

      static <K, V> OrderedMap<K,V> of()
      Returns an empty OrderedMap.
      Type Parameters:
      K - key type
      V - value type
      Returns:
      empty map
    • of

      static <K, V> OrderedMap<K,V> of(K k1, V v1)
      Returns an OrderedMap with a single mapping.
      Type Parameters:
      K - key type
      V - value type
      Parameters:
      k1 - key
      v1 - value
      Returns:
      an OrderedMap of the provided mapping
      Throws:
      NullPointerException - if key or value are null
    • of

      static <K, V> OrderedMap<K,V> of(K k1, V v1, K k2, V v2)
      Returns an OrderedMap with two mappings.
      Type Parameters:
      K - key type
      V - value type
      Parameters:
      k1 - first key
      v1 - first value
      k2 - second key
      v2 - second value
      Returns:
      an OrderedMap of the provided mappings
      Throws:
      NullPointerException - if any keys or values are null
      IllegalArgumentException - if any keys are duplicated
    • of

      static <K, V> OrderedMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3)
      Returns an OrderedMap with three mappings.
      Type Parameters:
      K - key type
      V - value type
      Parameters:
      k1 - first key
      v1 - first value
      k2 - second key
      v2 - second value
      k3 - third key
      v3 - third value
      Returns:
      an OrderedMap of the provided mappings
      Throws:
      NullPointerException - if any keys or values are null
      IllegalArgumentException - if any keys are duplicated
    • of

      static <K, V> OrderedMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)
      Returns an OrderedMap with four mappings.
      Type Parameters:
      K - key type
      V - value type
      Parameters:
      k1 - first key
      v1 - first value
      k2 - second key
      v2 - second value
      k3 - third key
      v3 - third value
      k4 - fourth key
      v4 - fourth value
      Returns:
      an OrderedMap of the provided mappings
      Throws:
      NullPointerException - if any keys or values are null
      IllegalArgumentException - if any keys are duplicated
    • of

      static <K, V> OrderedMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)
      Returns an OrderedMap with five mappings.
      Type Parameters:
      K - key type
      V - value type
      Parameters:
      k1 - first key
      v1 - first value
      k2 - second key
      v2 - second value
      k3 - third key
      v3 - third value
      k4 - fourth key
      v4 - fourth value
      k5 - fifth key
      v5 - fifth value
      Returns:
      an OrderedMap of the provided mappings
      Throws:
      NullPointerException - if any keys or values are null
      IllegalArgumentException - if any keys are duplicated
    • ofEntries

      @SafeVarargs static <K, V> OrderedMap<K,V> ofEntries(Map.Entry<? extends K,? extends V>... entries)
      Returns an OrderedMap from the given entries. The entries themselves are not stored in the map.
      Type Parameters:
      K - key type
      V - value type
      Parameters:
      entries - map entries
      Returns:
      an OrderedMap of the provided mappings
      Throws:
      NullPointerException - if any keys or values are null, or if entries is null
      IllegalArgumentException - if any keys are duplicated
    • copyOf

      static <K, V> OrderedMap<K,V> copyOf(Map<? extends K,? extends V> map)
      Return an OrderedMap that contains a copy of the provided Map. The order will be the same as the iteration order of the map's entry set.

      If the map is already an unmodifiable OrderedMap it may be returned as is.

      Type Parameters:
      K - key type
      V - value type
      Parameters:
      map - map to copy
      Returns:
      an ordered map copy of the provided map