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
- Direct Known Subclasses:
ImmutableOffsetMapTemplate
,SharedSingletonMapTemplate
public abstract sealed class ImmutableMapTemplate<K>
extends Object
implements Immutable
permits ImmutableOffsetMapTemplate<K>, SharedSingletonMapTemplate<K>
Template for instantiating
UnmodifiableMapPhase
instances with a fixed set of keys. The template can then be
used as a factory for instances via using instantiateTransformed(Map, BiFunction)
or, more efficiently,
using instantiateWithValues(Object[])
where the argument array has values ordered corresponding to the key
order defined by keySet()
.
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 using ImmutableOffsetMapTemplate
.
-
Method Summary
Modifier and TypeMethodDescriptionabstract <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.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 Details
-
ordered
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
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
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
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:
-