Package org.opendaylight.yangtools.util
Class ImmutableOffsetMap<K,V>
java.lang.Object
org.opendaylight.yangtools.util.ImmutableOffsetMap<K,V>
- Type Parameters:
K
- the type of keys maintained by this mapV
- the type of mapped values
- All Implemented Interfaces:
Serializable
,Map<K,
,V> Immutable
,UnmodifiableMapPhase<K,
V>
public abstract sealed class ImmutableOffsetMap<K,V>
extends Object
implements UnmodifiableMapPhase<K,V>, Serializable
Implementation of the
Map
interface which stores a set of immutable mappings using a key-to-offset map and
a backing array. This is useful for situations where the same key set is shared across a multitude of maps, as this
class uses a global cache to share the key-to-offset mapping.
In case the set of keys is statically known, you can use ImmutableOffsetMapTemplate
to efficiently create
ImmutableOffsetMap
instances.
- See Also:
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
clear()
final boolean
containsKey
(Object key) final boolean
containsValue
(Object value) entrySet()
final boolean
final V
final int
hashCode()
final boolean
isEmpty()
keySet()
static <K,
V> @NonNull Map<K, V> orderedCopyOf
(@NonNull Map<K, V> map) Create anImmutableOffsetMap
as a copy of an existing map.final V
final void
final V
final int
size()
abstract @NonNull MutableOffsetMap<K,
V> Return an isolated modifiable version of this map.final String
toString()
static <K,
V> @NonNull Map<K, V> unorderedCopyOf
(@NonNull Map<K, V> map) Create anImmutableOffsetMap
as a copy of an existing map.final @NonNull Collection<V>
values()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Method Details
-
toModifiableMap
Description copied from interface:UnmodifiableMapPhase
Return an isolated modifiable version of this map. Its mappings must match the mappings present in this map. Any modification of the returned map must not be affect the contents of this map.- Specified by:
toModifiableMap
in interfaceUnmodifiableMapPhase<K,
V> - Returns:
- An modifiable version of this map.
-
orderedCopyOf
Create anImmutableOffsetMap
as a copy of an existing map. This is actually not completely true, as this method returns anImmutableMap
for empty and singleton inputs, as those are more memory-efficient. This method also recognizesImmutableOffsetMap
andSharedSingletonMap
on input, and returns it back without doing anything else. It also recognizesMutableOffsetMap
(as returned bytoModifiableMap()
) and makes an efficient copy of its contents. All other maps are converted to anImmutableOffsetMap
with the same iteration order as input.- Type Parameters:
K
- the type of keys maintained by the mapV
- the type of mapped values- Parameters:
map
- Input map, may not be null.- Returns:
- An isolated, immutable copy of the input map
- Throws:
NullPointerException
- ifmap
or any of its elements is null.
-
unorderedCopyOf
Create anImmutableOffsetMap
as a copy of an existing map. This is actually not completely true, as this method returns anImmutableMap
for empty and singleton inputs, as those are more memory-efficient. This method also recognizesImmutableOffsetMap
andSharedSingletonMap
on input, and returns it back without doing anything else. It also recognizesMutableOffsetMap
(as returned bytoModifiableMap()
) and makes an efficient copy of its contents. All other maps are converted to anImmutableOffsetMap
. Iterator order is not guaranteed to be retained.- Type Parameters:
K
- the type of keys maintained by the mapV
- the type of mapped values- Parameters:
map
- Input map, may not be null.- Returns:
- An isolated, immutable copy of the input map
- Throws:
NullPointerException
- ifmap
or any of its elements is null.
-
size
public final int size() -
isEmpty
public final boolean isEmpty() -
hashCode
public final int hashCode() -
equals
-
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V>
-
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V>
-
get
-
remove
-
put
-
putAll
-
clear
public final void clear() -
keySet
-
values
-
entrySet
-
toString
-