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.
-
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 TypeMethodDescriptionvoidclear()booleancontainsKey(int instanceId, Object key) Returnstrueif this map contains a mapping for the specified instance id.booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()voidforEach(BiConsumer<? super K, ? super V> action) @Nullable VReturns the value to which the specified instance id is mapped, ornullif this map contains no mapping for the instance id.@Nullable VbooleanisEmpty()keySet()@Nullable Vvoid@Nullable VputIfAbsent(K key, V value) @Nullable VRemoves the mapping for an instance id from this map if it is present (optional operation).@Nullable Vintsize()toArray()@NonNull Collection<V> values()Methods inherited from class org.hibernate.internal.util.collections.AbstractPagedArray
get, getOrCreateEntryPage, getPage, set, toPageIndex, toPageOffsetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
sizein interfaceMap<K extends InstanceIdentity,V>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceMap<K extends InstanceIdentity,V>
-
containsKey
Returnstrueif 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:
trueif 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:
containsKeyin interfaceMap<K extends InstanceIdentity,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K extends InstanceIdentity,V>
-
get
Returns the value to which the specified instance id is mapped, ornullif 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
nullif 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:
getin interfaceMap<K extends InstanceIdentity,V>
-
put
- Specified by:
putin 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, ornullif 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:
removein interfaceMap<K extends InstanceIdentity,V>
-
putAll
- Specified by:
putAllin interfaceMap<K extends InstanceIdentity,V>
-
putIfAbsent
- Specified by:
putIfAbsentin interfaceMap<K extends InstanceIdentity,V>
-
clear
public void clear()- Specified by:
clearin interfaceMap<K extends InstanceIdentity,V> - Overrides:
clearin classAbstractPagedArray<Map.Entry<K extends InstanceIdentity,V>>
-
keySet
- Specified by:
keySetin interfaceMap<K extends InstanceIdentity,V>
-
values
- Specified by:
valuesin interfaceMap<K extends InstanceIdentity,V>
-
entrySet
- Specified by:
entrySetin interfaceMap<K extends InstanceIdentity,V>
-
forEach
- Specified by:
forEachin interfaceMap<K extends InstanceIdentity,V>
-
toArray
-