Class InstanceIdentityStore<V>

java.lang.Object
org.hibernate.internal.util.collections.AbstractPagedArray<Object>
org.hibernate.internal.util.collections.InstanceIdentityStore<V>
Type Parameters:
V - the type of values contained in this store

public class InstanceIdentityStore<V> extends AbstractPagedArray<Object>
Utility collection that takes advantage of InstanceIdentity's identifier to store objects. The store is based on AbstractPagedArray and it stores element using their instance-id as index.

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

Both keys and values are stored in this array, requiring very few allocations to keep track of the pair. The downside to this is we cannot easily access the key, especially if asking for a specific type, since that would cause type-pollution issues at the call site that would degrade performance.

  • Constructor Details

    • InstanceIdentityStore

      public InstanceIdentityStore()
  • Method Details

    • get

      public @Nullable V get(int instanceId, Object key)
      Returns the value to which the specified instance id is mapped, or null if this store 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
    • put

      public void put(Object key, int instanceId, V value)
      Associates the specified value with the specified key in this store (optional operation). If the store previously contained a mapping for the key, the old value is replaced by the specified value.
      Parameters:
      key - key with which the specified value is to be associated
      value - value to be associated with the specified key
    • remove

      public void remove(int instanceId, Object key)
      Removes the mapping for an instance id from this store 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
      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