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.Entry
s 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.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.hibernate.internal.util.collections.AbstractPagedArray
AbstractPagedArray.Page<E>, AbstractPagedArray.PagedArrayIterator<T>
-
Field Summary
Fields inherited from class org.hibernate.internal.util.collections.AbstractPagedArray
elementPages
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
boolean
containsKey
(int instanceId, Object key) Returnstrue
if this map contains a mapping for the specified instance id.boolean
containsKey
(Object key) boolean
containsValue
(Object value) entrySet()
void
forEach
(BiConsumer<? super K, ? super V> action) @Nullable V
Returns the value to which the specified instance id is mapped, ornull
if this map contains no mapping for the instance id.@Nullable V
boolean
isEmpty()
keySet()
@Nullable V
void
@Nullable V
putIfAbsent
(K key, V value) @Nullable V
Removes the mapping for an instance id from this map if it is present (optional operation).@Nullable V
int
size()
toArray()
@NonNull Collection<V>
values()
Methods inherited from class org.hibernate.internal.util.collections.AbstractPagedArray
get, getOrCreateEntryPage, getPage, set, toPageIndex, toPageOffset
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, getOrDefault, hashCode, merge, remove, replace, replace, replaceAll
-
Constructor Details
-
InstanceIdentityMap
public InstanceIdentityMap()
-
-
Method Details
-
size
public int size()- Specified by:
size
in interfaceMap<K extends InstanceIdentity,
V>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceMap<K extends InstanceIdentity,
V>
-
containsKey
Returnstrue
if this map contains a mapping for the specified instance id.- Parameters:
instanceId
- the instance id whose associated value is to be returnedkey
- 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
- Specified by:
containsKey
in interfaceMap<K extends InstanceIdentity,
V>
-
containsValue
- Specified by:
containsValue
in interfaceMap<K extends InstanceIdentity,
V>
-
get
Returns the value to which the specified instance id is mapped, ornull
if this map contains no mapping for the instance id.- Parameters:
instanceId
- the instance id whose associated value is to be returnedkey
- 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
- Specified by:
get
in interfaceMap<K extends InstanceIdentity,
V>
-
put
- Specified by:
put
in interfaceMap<K extends InstanceIdentity,
V>
-
remove
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 returnedkey
- key instance to double-check instance equality- Returns:
- the previous value associated with
instanceId
, ornull
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
- Specified by:
remove
in interfaceMap<K extends InstanceIdentity,
V>
-
putAll
- Specified by:
putAll
in interfaceMap<K extends InstanceIdentity,
V>
-
putIfAbsent
- Specified by:
putIfAbsent
in interfaceMap<K extends InstanceIdentity,
V>
-
clear
public void clear()- Specified by:
clear
in interfaceMap<K extends InstanceIdentity,
V> - Overrides:
clear
in classAbstractPagedArray<Map.Entry<K extends InstanceIdentity,
V>>
-
keySet
- Specified by:
keySet
in interfaceMap<K extends InstanceIdentity,
V>
-
values
- Specified by:
values
in interfaceMap<K extends InstanceIdentity,
V>
-
entrySet
- Specified by:
entrySet
in interfaceMap<K extends InstanceIdentity,
V>
-
forEach
- Specified by:
forEach
in interfaceMap<K extends InstanceIdentity,
V>
-
toArray
-