Class ImmutableOffsetMap<K,V>

java.lang.Object
org.opendaylight.yangtools.util.ImmutableOffsetMap<K,V>
Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values
All Implemented Interfaces:
Serializable, Map<K,V>, Immutable, UnmodifiableMapPhase<K,V>

public abstract sealed class ImmutableOffsetMap<K,V> extends Object implements UnmodifiableMapPhase<K,V>, Serializable
Implementation of the Map interface which stores a set of immutable mappings using a key-to-offset map and a backing array. This is useful for situations where the same key set is shared across a multitude of maps, as this class uses a global cache to share the key-to-offset mapping.

In case the set of keys is statically known, you can use ImmutableOffsetMapTemplate to efficiently create ImmutableOffsetMap instances.

See Also:
  • Method Details

    • toModifiableMap

      public abstract @NonNull MutableOffsetMap<K,V> toModifiableMap()
      Description copied from interface: UnmodifiableMapPhase
      Return an isolated modifiable version of this map. Its mappings must match the mappings present in this map. Any modification of the returned map must not be affect the contents of this map.
      Specified by:
      toModifiableMap in interface UnmodifiableMapPhase<K,V>
      Returns:
      An modifiable version of this map.
    • orderedCopyOf

      public static <K, V> @NonNull Map<K,V> orderedCopyOf(@NonNull Map<K,V> map)
      Create an ImmutableOffsetMap as a copy of an existing map. This is actually not completely true, as this method returns an ImmutableMap for empty and singleton inputs, as those are more memory-efficient. This method also recognizes ImmutableOffsetMap and SharedSingletonMap on input, and returns it back without doing anything else. It also recognizes MutableOffsetMap (as returned by toModifiableMap()) and makes an efficient copy of its contents. All other maps are converted to an ImmutableOffsetMap with the same iteration order as input.
      Type Parameters:
      K - the type of keys maintained by the map
      V - the type of mapped values
      Parameters:
      map - Input map, may not be null.
      Returns:
      An isolated, immutable copy of the input map
      Throws:
      NullPointerException - if map or any of its elements is null.
    • unorderedCopyOf

      public static <K, V> @NonNull Map<K,V> unorderedCopyOf(@NonNull Map<K,V> map)
      Create an ImmutableOffsetMap as a copy of an existing map. This is actually not completely true, as this method returns an ImmutableMap for empty and singleton inputs, as those are more memory-efficient. This method also recognizes ImmutableOffsetMap and SharedSingletonMap on input, and returns it back without doing anything else. It also recognizes MutableOffsetMap (as returned by toModifiableMap()) and makes an efficient copy of its contents. All other maps are converted to an ImmutableOffsetMap. Iterator order is not guaranteed to be retained.
      Type Parameters:
      K - the type of keys maintained by the map
      V - the type of mapped values
      Parameters:
      map - Input map, may not be null.
      Returns:
      An isolated, immutable copy of the input map
      Throws:
      NullPointerException - if map or any of its elements is null.
    • size

      public final int size()
      Specified by:
      size in interface Map<K,V>
    • isEmpty

      public final boolean isEmpty()
      Specified by:
      isEmpty in interface Map<K,V>
    • hashCode

      public final int hashCode()
      Specified by:
      hashCode in interface Map<K,V>
      Overrides:
      hashCode in class Object
    • equals

      public final boolean equals(Object obj)
      Specified by:
      equals in interface Map<K,V>
      Overrides:
      equals in class Object
    • containsKey

      public final boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<K,V>
    • containsValue

      public final boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map<K,V>
    • get

      public final V get(Object key)
      Specified by:
      get in interface Map<K,V>
    • remove

      public final V remove(Object key)
      Specified by:
      remove in interface Map<K,V>
    • put

      public final V put(K key, V value)
      Specified by:
      put in interface Map<K,V>
    • putAll

      public final void putAll(Map<? extends K,? extends V> m)
      Specified by:
      putAll in interface Map<K,V>
    • clear

      public final void clear()
      Specified by:
      clear in interface Map<K,V>
    • keySet

      public final Set<K> keySet()
      Specified by:
      keySet in interface Map<K,V>
    • values

      public final @NonNull Collection<V> values()
      Specified by:
      values in interface Map<K,V>
    • entrySet

      public final @NonNull Set<Map.Entry<K,V>> entrySet()
      Specified by:
      entrySet in interface Map<K,V>
    • toString

      public final String toString()
      Overrides:
      toString in class Object