Package org.opendaylight.yangtools.util
Class ImmutableMapTemplate<K>
- java.lang.Object
-
- org.opendaylight.yangtools.util.ImmutableMapTemplate<K>
-
- Type Parameters:
K
- the type of keys maintained by this template
- All Implemented Interfaces:
Immutable
,MutationBehaviour<Immutable>
- Direct Known Subclasses:
ImmutableOffsetMapTemplate
,SharedSingletonMapTemplate
@Beta public abstract class ImmutableMapTemplate<K> extends Object implements Immutable
Template for instantiatingUnmodifiableMapPhase
instances with a fixed set of keys. The template can then be used as a factory for instances via usinginstantiateTransformed(Map, BiFunction)
or, more efficiently, usinginstantiateWithValues(Object[])
where the argument array has values ordered corresponding to the key order defined bykeySet()
.If the keySet is static known to contain only a single key, consider using
SharedSingletonMapTemplate
. If it is statically known to contain multiple keys, consider usingImmutableOffsetMapTemplate
.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract <T,V>
@NonNull UnmodifiableMapPhase<K,V>instantiateTransformed(Map<K,T> fromMap, BiFunction<K,T,V> keyValueTransformer)
Instantiate an immutable map by applying specifiedtransformer
to values offromMap
.abstract <V> @NonNull UnmodifiableMapPhase<K,V>
instantiateWithValues(V... values)
Instantiate an immutable map by filling values from provided array.abstract Set<K>
keySet()
Returns the set of keys expected by this template, in the iteration order Maps resulting from instantiation will have.static <K> @NonNull ImmutableMapTemplate<K>
ordered(Collection<K> keys)
Create a template which produces Maps with specified keys, with iteration order matching the iteration order ofkeys
.static <K> @NonNull ImmutableMapTemplate<K>
unordered(Collection<K> keys)
Create a template which produces Maps with specified keys, with unconstrained iteration order.
-
-
-
Method Detail
-
ordered
public static <K> @NonNull ImmutableMapTemplate<K> ordered(Collection<K> keys)
Create a template which produces Maps with specified keys, with iteration order matching the iteration order ofkeys
.keySet()
will return these keys in exactly the same order. The resulting map will retain insertion order throughUnmodifiableMapPhase.toModifiableMap()
transformations.- Type Parameters:
K
- the type of keys maintained by resulting template- Parameters:
keys
- Keys in requested iteration order.- Returns:
- A template object.
- Throws:
NullPointerException
- ifkeys
or any of its elements is nullIllegalArgumentException
- ifkeys
is empty
-
unordered
public static <K> @NonNull ImmutableMapTemplate<K> unordered(Collection<K> keys)
Create a template which produces Maps with specified keys, with unconstrained iteration order. Produced maps will have the iteration order matching the order returned bykeySet()
. The resulting map will NOT retain ordering throughUnmodifiableMapPhase.toModifiableMap()
transformations.- Type Parameters:
K
- the type of keys maintained by resulting template- Parameters:
keys
- Keys in any iteration order.- Returns:
- A template object.
- Throws:
NullPointerException
- ifkeys
or any of its elements is nullIllegalArgumentException
- ifkeys
is empty
-
instantiateTransformed
public abstract <T,V> @NonNull UnmodifiableMapPhase<K,V> instantiateTransformed(Map<K,T> fromMap, BiFunction<K,T,V> keyValueTransformer)
Instantiate an immutable map by applying specifiedtransformer
to values offromMap
.- Type Parameters:
T
- the type of input valuesV
- the type of mapped values- Parameters:
fromMap
- Input mapkeyValueTransformer
- Transformation to apply to values- Returns:
- An immutable map
- Throws:
NullPointerException
- if any of the arguments is null or if the transformer produces anull
valueIllegalArgumentException
- iffromMap#keySet()
does not match this template's keys
-
instantiateWithValues
public abstract <V> @NonNull UnmodifiableMapPhase<K,V> instantiateWithValues(V... values)
Instantiate an immutable map by filling values from provided array. The array MUST be ordered to match key order as returned bykeySet()
.- Type Parameters:
V
- the type of mapped values- Parameters:
values
- Values to use- Returns:
- An immutable map
- Throws:
NullPointerException
- ifvalues
or any of its elements is nullIllegalArgumentException
- ifvalues.length
does not match the number of keys in this template
-
keySet
public abstract Set<K> keySet()
Returns the set of keys expected by this template, in the iteration order Maps resulting from instantiation will have.- Returns:
- This template's key set
- See Also:
Map.keySet()
-
-