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
,MutationBehaviour<Immutable>
,UnmodifiableMapPhase<K,V>
@Beta public abstract class ImmutableOffsetMap<K,V> extends Object implements UnmodifiableMapPhase<K,V>, Serializable
Implementation of theMap
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 createImmutableOffsetMap
instances.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
containsKey(Object key)
boolean
containsValue(Object value)
@NonNull Set<Map.Entry<K,V>>
entrySet()
boolean
equals(Object obj)
V
get(Object key)
int
hashCode()
boolean
isEmpty()
Set<K>
keySet()
static <K,V>
@NonNull Map<K,V>orderedCopyOf(@NonNull Map<K,V> map)
Create anImmutableOffsetMap
as a copy of an existing map.V
put(K key, V value)
void
putAll(Map<? extends K,? extends V> m)
V
remove(Object key)
int
size()
abstract @NonNull MutableOffsetMap<K,V>
toModifiableMap()
Return an isolated modifiable version of this map.String
toString()
static <K,V>
@NonNull Map<K,V>unorderedCopyOf(@NonNull Map<K,V> map)
Create anImmutableOffsetMap
as a copy of an existing map.@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 Detail
-
toModifiableMap
public abstract @NonNull MutableOffsetMap<K,V> 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
public static <K,V> @NonNull Map<K,V> orderedCopyOf(@NonNull Map<K,V> map)
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.- 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
public static <K,V> @NonNull Map<K,V> unorderedCopyOf(@NonNull Map<K,V> map)
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.- 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.
-
hashCode
public final int hashCode()
-
equals
public final boolean equals(Object obj)
-
containsKey
public final boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<K,V>
-
containsValue
public final boolean containsValue(Object value)
- Specified by:
containsValue
in interfaceMap<K,V>
-
-