Top Description Fields Constructors Methods
org.hibernate.internal.util.collections

public abstract Class LazyIndexedMap<K, V>

extends Object
Class Inheritance
Known Direct Subclasses
org.hibernate.internal.util.collections.LockModeEnumMap, org.hibernate.persister.entity.EntityLoaderLazyCollection
Type Parameters
<K>
the types used to model the key
<V>
the types used to model the value
Imports
java.util.Arrays, java.util.function.Function

This is an internal data structure designed for very specific needs; it will most often be used as a replacement for EnumMap, although the focus on the Enum aspect is modelled as an int primitive: think of using the ordinals of an Enum to simulate the EnumMap. Proper abstraction of the indexing strategy is left to subclasses.

There are various reasons to not expose the Enum on this class API; the primary is that in some of the cases in which we need the pattern, there is the need to hold an additional couple of values beyond the ones modelled by the Enum, essentially having some extra keys in the map; this could be modelled by defining a new Enum but that's also not ideal.

Another reason is that the goal of this class is to allow the host to save memory, as we typically need to keep references to many of these objects for a long time; being able to refer purely to an array is less practical but gets us benefits in memory layout and total retained memory.

Field Summary

Modifier and TypeField and Description
private static final Object
private volatile Object[]

Constructor Summary

AccessConstructor and Description
protected
LazyIndexedMap(final int size)

Method Summary

Modifier and TypeMethod and Description
protected <K1 extends K> V

Returns:

the associated value to this index/key.
computeIfAbsent
(final int
storage index in the array
index
,
final K1
the original key object, used to efficiently pass it into the valueGenerator function
originalKey
,
final Function<K1, V>
if no value was generated before for this index, then the valueGenerator is invoked to associate a new value and store it into the internal array at the provided index.
valueGenerator
)

Both the index and the original key are requested for efficiency reasons.

private synchronized <K1 extends K> V
lockedComputeIfAbsent(final int index, final K1 originalKey, final Function<K1, V> valueGenerator)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

NOT_INITIALIZEDback to summary
private static final Object NOT_INITIALIZED
valuesback to summary
private volatile Object[] values

Constructor Detail

LazyIndexedMapback to summary
protected LazyIndexedMap(final int size)

Method Detail

computeIfAbsentback to summary
protected <K1 extends K> V computeIfAbsent(final int index, final K1 originalKey, final Function<K1, V> valueGenerator)

Both the index and the original key are requested for efficiency reasons. It is the responsibility of the caller to ensure there is a 1:1 matching relation between them.

Parameters
index:int

storage index in the array

originalKey:K1

the original key object, used to efficiently pass it into the valueGenerator function

valueGenerator:Function<K1, V>

if no value was generated before for this index, then the valueGenerator is invoked to associate a new value and store it into the internal array at the provided index.

Returns:V

the associated value to this index/key.

lockedComputeIfAbsentback to summary
private synchronized <K1 extends K> V lockedComputeIfAbsent(final int index, final K1 originalKey, final Function<K1, V> valueGenerator)