Package org.opendaylight.yangtools.util
Class MutableOffsetMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- org.opendaylight.yangtools.util.MutableOffsetMap<K,V>
-
- Type Parameters:
K
- the type of keys maintained by this mapV
- the type of mapped values
- All Implemented Interfaces:
Cloneable
,Map<K,V>
,Mutable
,MutationBehaviour<Mutable>
,ModifiableMapPhase<K,V>
@Beta public abstract class MutableOffsetMap<K,V> extends AbstractMap<K,V> implements Cloneable, ModifiableMapPhase<K,V>
A mutable version ofImmutableOffsetMap
. It inherits the set of mappings from the immutable version and allows updating/removing existing mappings. New mappings are stored in a dedicatedLinkedHashMap
to preserve insertion order. It also tracks the need to duplicate the backing array, so the sequence ofImmutableOffsetMap<K, V> source; ImmutableOffsetMap<K, V> result = source.createMutableClone().immutableCopy();
results in source and result sharing the backing objects.This map does not support null keys nor values.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
MutableOffsetMap<K,V>
clone()
boolean
containsKey(Object key)
@NonNull Set<Map.Entry<K,V>>
entrySet()
boolean
equals(Object obj)
V
get(Object key)
int
hashCode()
boolean
isEmpty()
@NonNull Set<K>
keySet()
static <K,V>
@NonNull MutableOffsetMap<K,V>ordered()
Create an emptyMutableOffsetMap
which has an iteration order matching the insertion order.static <K,V>
@NonNull MutableOffsetMap<K,V>orderedCopyOf(Map<K,V> map)
Create aMutableOffsetMap
of the specified map, retaining its iteration order.V
put(K key, V value)
V
remove(Object key)
int
size()
@NonNull Map<K,V>
toUnmodifiableMap()
Return an isolated unmodifiable version of this map.static <K,V>
@NonNull MutableOffsetMap<K,V>unordered()
Create an emptyMutableOffsetMap
which has unspecified iteration order.static <K,V>
@NonNull MutableOffsetMap<K,V>unorderedCopyOf(Map<K,V> map)
Create aMutableOffsetMap
of the specified map, potentially with a different iteration order.-
Methods inherited from class java.util.AbstractMap
containsValue, putAll, toString, values
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsValue, forEach, getOrDefault, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll, values
-
-
-
-
Method Detail
-
orderedCopyOf
public static <K,V> @NonNull MutableOffsetMap<K,V> orderedCopyOf(Map<K,V> map)
Create aMutableOffsetMap
of the specified map, retaining its iteration order.- Parameters:
map
- input map- Returns:
- MutableOffsetMap with the same iteration order
- Throws:
NullPointerException
- ifmap
is null
-
unorderedCopyOf
public static <K,V> @NonNull MutableOffsetMap<K,V> unorderedCopyOf(Map<K,V> map)
Create aMutableOffsetMap
of the specified map, potentially with a different iteration order.- Parameters:
map
- input map- Returns:
- MutableOffsetMap with undefined iteration order
- Throws:
NullPointerException
- ifmap
is null
-
ordered
public static <K,V> @NonNull MutableOffsetMap<K,V> ordered()
Create an emptyMutableOffsetMap
which has an iteration order matching the insertion order.- Returns:
- MutableOffsetMap which preserves insertion order
-
unordered
public static <K,V> @NonNull MutableOffsetMap<K,V> unordered()
Create an emptyMutableOffsetMap
which has unspecified iteration order.- Returns:
- An MutableOffsetMap
-
size
public final int size()
-
isEmpty
public final boolean isEmpty()
-
containsKey
public final boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<K,V>
- Overrides:
containsKey
in classAbstractMap<K,V>
-
clear
public final void clear()
-
toUnmodifiableMap
public @NonNull Map<K,V> toUnmodifiableMap()
Description copied from interface:ModifiableMapPhase
Return an isolated unmodifiable version of this map. Returned object must not allow removal, addition or changing of mappings. Its mappings must match the mappings currently present in this map, but must not be affected by any subsequent changes to this map.- Specified by:
toUnmodifiableMap
in interfaceModifiableMapPhase<K,V>
- Returns:
- An unmodifiable version of this map.
-
clone
public MutableOffsetMap<K,V> clone()
- Overrides:
clone
in classAbstractMap<K,V>
-
hashCode
public final int hashCode()
-
equals
public final boolean equals(Object obj)
-
-