Class InstanceIdentityMap<K extends InstanceIdentity,V>

java.lang.Object
org.hibernate.internal.util.collections.AbstractPagedArray<Map.Entry<K,V>>
org.hibernate.internal.util.collections.InstanceIdentityMap<K,V>
All Implemented Interfaces:
Map<K,V>

public class InstanceIdentityMap<K extends InstanceIdentity,V> extends AbstractPagedArray<Map.Entry<K,V>> implements Map<K,V>
Map implementation of based on InstanceIdentity, similar to InstanceIdentityStore. This collection also stores values using an array-like structure that automatically grows as needed but, contrary to the store, it initializes Map.Entrys eagerly to optimize iteration performance and avoid type-pollution issues when checking the type of contained objects.

Instance ids are considered to start from 1, and if two instances are found to have the same identifier a will be thrown.

Methods accessing / modifying the map with Object typed parameters will need to type check against the instance identity interface which might be inefficient, so it's recommended to use the position (int) based variant of those methods.

  • Constructor Details

    • InstanceIdentityMap

      public InstanceIdentityMap()
  • Method Details

    • size

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

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<K extends InstanceIdentity,V>
    • containsKey

      public boolean containsKey(int instanceId, Object key)
      Returns true if this map contains a mapping for the specified instance id.
      Parameters:
      instanceId - the instance id whose associated value is to be returned
      key - key instance to double-check instance equality
      Returns:
      true if this map contains a mapping for the specified instance id
      Implementation Note:
      This method accesses the backing array with the provided instance id, but performs an instance equality check (==) with the provided key to ensure it corresponds to the mapped one
    • containsKey

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

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

      public @Nullable V get(int instanceId, Object key)
      Returns the value to which the specified instance id is mapped, or null if this map contains no mapping for the instance id.
      Parameters:
      instanceId - the instance id whose associated value is to be returned
      key - key instance to double-check instance equality
      Returns:
      the value to which the specified instance id is mapped, or null if this map contains no mapping for the instance id
      Implementation Note:
      This method accesses the backing array with the provided instance id, but performs an instance equality check (==) with the provided key to ensure it corresponds to the mapped one
    • get

      public @Nullable V get(Object key)
      Specified by:
      get in interface Map<K extends InstanceIdentity,V>
    • put

      public @Nullable V put(K key, V value)
      Specified by:
      put in interface Map<K extends InstanceIdentity,V>
    • remove

      public @Nullable V remove(int instanceId, Object key)
      Removes the mapping for an instance id from this map if it is present (optional operation).
      Parameters:
      instanceId - the instance id whose associated value is to be returned
      key - key instance to double-check instance equality
      Returns:
      the previous value associated with instanceId, or null if there was no mapping for it.
      Implementation Note:
      This method accesses the backing array with the provided instance id, but performs an instance equality check (==) with the provided key to ensure it corresponds to the mapped one
    • remove

      public @Nullable V remove(Object key)
      Specified by:
      remove in interface Map<K extends InstanceIdentity,V>
    • putAll

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

      public @Nullable V putIfAbsent(K key, V value)
      Specified by:
      putIfAbsent in interface Map<K extends InstanceIdentity,V>
    • clear

      public void clear()
      Specified by:
      clear in interface Map<K extends InstanceIdentity,V>
      Overrides:
      clear in class AbstractPagedArray<Map.Entry<K extends InstanceIdentity,V>>
    • keySet

      public @NonNull Set<K> keySet()
      Specified by:
      keySet in interface Map<K extends InstanceIdentity,V>
    • values

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

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

      public void forEach(BiConsumer<? super K,? super V> action)
      Specified by:
      forEach in interface Map<K extends InstanceIdentity,V>
    • toArray

      public Map.Entry<K,V>[] toArray()