Class BindingMap
- java.lang.Object
-
- org.opendaylight.yangtools.yang.binding.util.BindingMap
-
@Beta public final class BindingMap extends Object
Utility class for instantiating Maps containingIdentifiable
values. Unlike normal Map instantiation utilities, methods in this class index values via their identifier, hence providing a more convenient API, amenable to fluent builders.A typical example of use with generated DataObjects looks like this:
Foo foo = new FooBuilder() .setBar(BindingMap.of( new BarBuilder().setName("one").build(), new BarBuilder().setName("two").build())) .build();
Another alternative is to use builders:
Foo foo = new FooBuilder() .setBar(BindingMap.<BarKey, Bar>builder() .add(new BarBuilder().setName("one").build()) .add(new BarBuilder().setName("two").build()) .build()) .build();
This class allows for two modes of operation:
- Unordered, available through
of(Identifiable...)
/builder()
family of functions. Maps instantiated through this, preferred, interface will have their iteration order randomized, as explain in Java 9+ unmodifiable collections. - Ordered, available through
ordered(Identifiable...)
/orderedBuilder()
family of functions. Maps instantiated through this interface have a predictable iteration order, as perImmutableMap
class design. The use of this interface is generally discouraged, as it may lead to code relying on map iteration order. Nevertheless it may prove useful where the goal is to have predictable outcomes and hence is provided for completeness.
- Unordered, available through
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BindingMap.Builder<K extends Identifier<V>,V extends Identifiable<K>>
Builder producing a Map containing bindingIdentifiable
values.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull BindingMap.Builder<K,V>builder()
Create a builder on an unmodifiable map, which does not retain value insertion order.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull BindingMap.Builder<K,V>builder(int expectedSize)
Create a builder on an unmodifiable map, which does not retain value insertion order.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Map<K,V>of(Collection<V> values)
Returns an unmodifiable map containing given values.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Map<K,V>of(V v1)
Returns an unmodifiable map containing a single mapping.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Map<K,V>of(V... values)
Returns an unmodifiable map containing given values.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Map<K,V>of(V v1, V v2)
Returns an unmodifiable map containing two mappings.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Map<K,V>of(V v1, V v2, V v3)
Returns an unmodifiable map containing three mappings.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Map<K,V>of(V v1, V v2, V v3, V v4)
Returns an unmodifiable map containing four mappings.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Map<K,V>of(V v1, V v2, V v3, V v4, V v5)
Returns an unmodifiable map containing five mappings.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Map<K,V>of(V v1, V v2, V v3, V v4, V v5, V v6)
Returns an unmodifiable map containing six mappings.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Map<K,V>of(V v1, V v2, V v3, V v4, V v5, V v6, V v7)
Returns an unmodifiable map containing seven mappings.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Map<K,V>of(V v1, V v2, V v3, V v4, V v5, V v6, V v7, V v8)
Returns an unmodifiable map containing eight mappings.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Map<K,V>of(V v1, V v2, V v3, V v4, V v5, V v6, V v7, V v8, V v9)
Returns an unmodifiable map containing nine mappings.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Map<K,V>of(V v1, V v2, V v3, V v4, V v5, V v6, V v7, V v8, V v9, V v10)
Returns an unmodifiable map containing ten mappings.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Map<K,V>ordered(Collection<V> values)
Returns an unmodifiable map containing given values.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Map<K,V>ordered(V... values)
Returns an unmodifiable map containing given values.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Map<K,V>ordered(V v1, V v2)
Returns an unmodifiable map containing two mappings.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Map<K,V>ordered(V v1, V v2, V v3)
Returns an unmodifiable map containing three mappings.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Map<K,V>ordered(V v1, V v2, V v3, V v4)
Returns an unmodifiable map containing four mappings.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Map<K,V>ordered(V v1, V v2, V v3, V v4, V v5)
Returns an unmodifiable map containing five mappings.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull BindingMap.Builder<K,V>orderedBuilder()
Create a builder on an unmodifiable map, which retains value insertion order.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull BindingMap.Builder<K,V>orderedBuilder(int expectedSize)
Create a builder on an unmodifiable map, which retains value insertion order.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Collector<V,?,? extends Map<K,V>>toMap()
Returns a collector which collects bindingIdentifiable
objects into an unmodifiable map.static <K extends Identifier<V>,V extends Identifiable<K>>
@NonNull Collector<V,?,? extends Map<K,V>>toOrderedMap()
Returns a collector which collects bindingIdentifiable
objects into an unmodifiable map.
-
-
-
Method Detail
-
of
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Map<K,V> of(V v1)
Returns an unmodifiable map containing a single mapping.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
v1
- the mapping's value- Returns:
- a
Map
containing the specified value - Throws:
NullPointerException
- if the value isnull
-
of
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Map<K,V> of(V v1, V v2)
Returns an unmodifiable map containing two mappings. The resulting map is NOT guaranteed retain iteration order of mappings.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
v1
- the first mapping's valuev2
- the second mapping's value- Returns:
- a
Map
containing the specified mappings - Throws:
IllegalArgumentException
- if the values contain duplicate keysNullPointerException
- if any value isnull
-
of
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Map<K,V> of(V v1, V v2, V v3)
Returns an unmodifiable map containing three mappings. The resulting map is NOT guaranteed to retain iteration order of mappings.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
v1
- the first mapping's valuev2
- the second mapping's valuev3
- the third mapping's value- Returns:
- a
Map
containing the specified mappings - Throws:
IllegalArgumentException
- if the values contain duplicate keysNullPointerException
- if any value isnull
-
of
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Map<K,V> of(V v1, V v2, V v3, V v4)
Returns an unmodifiable map containing four mappings. The resulting map is NOT guaranteed to retain iteration order of mappings.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
v1
- the first mapping's valuev2
- the second mapping's valuev3
- the third mapping's valuev4
- the fourth mapping's value- Returns:
- a
Map
containing the specified mappings - Throws:
IllegalArgumentException
- if the values contain duplicate keysNullPointerException
- if any value isnull
-
of
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Map<K,V> of(V v1, V v2, V v3, V v4, V v5)
Returns an unmodifiable map containing five mappings. The resulting map is NOT guaranteed to retain iteration order of mappings.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
v1
- the first mapping's valuev2
- the second mapping's valuev3
- the third mapping's valuev4
- the fourth mapping's valuev5
- the fifth mapping's value- Returns:
- a
Map
containing the specified mappings - Throws:
IllegalArgumentException
- if the values contain duplicate keysNullPointerException
- if any value isnull
-
of
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Map<K,V> of(V v1, V v2, V v3, V v4, V v5, V v6)
Returns an unmodifiable map containing six mappings. The resulting map is NOT guaranteed to retain iteration order of mappings.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
v1
- the first mapping's valuev2
- the second mapping's valuev3
- the third mapping's valuev4
- the fourth mapping's valuev5
- the fifth mapping's valuev6
- the sixth mapping's value- Returns:
- a
Map
containing the specified mappings - Throws:
IllegalArgumentException
- if the values contain duplicate keysNullPointerException
- if any value isnull
-
of
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Map<K,V> of(V v1, V v2, V v3, V v4, V v5, V v6, V v7)
Returns an unmodifiable map containing seven mappings. The resulting map is NOT guaranteed to retain iteration order of mappings.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
v1
- the first mapping's valuev2
- the second mapping's valuev3
- the third mapping's valuev4
- the fourth mapping's valuev5
- the fifth mapping's valuev6
- the sixth mapping's valuev7
- the seventh mapping's value- Returns:
- a
Map
containing the specified mappings - Throws:
IllegalArgumentException
- if the values contain duplicate keysNullPointerException
- if any value isnull
-
of
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Map<K,V> of(V v1, V v2, V v3, V v4, V v5, V v6, V v7, V v8)
Returns an unmodifiable map containing eight mappings. The resulting map is NOT guaranteed to retain iteration order of mappings.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
v1
- the first mapping's valuev2
- the second mapping's valuev3
- the third mapping's valuev4
- the fourth mapping's valuev5
- the fifth mapping's valuev6
- the sixth mapping's valuev7
- the seventh mapping's valuev8
- the eighth mapping's value- Returns:
- a
Map
containing the specified mappings - Throws:
IllegalArgumentException
- if the values contain duplicate keysNullPointerException
- if any value isnull
-
of
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Map<K,V> of(V v1, V v2, V v3, V v4, V v5, V v6, V v7, V v8, V v9)
Returns an unmodifiable map containing nine mappings. The resulting map is NOT guaranteed to retain iteration order of mappings.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
v1
- the first mapping's valuev2
- the second mapping's valuev3
- the third mapping's valuev4
- the fourth mapping's valuev5
- the fifth mapping's valuev6
- the sixth mapping's valuev7
- the seventh mapping's valuev8
- the eighth mapping's valuev9
- the ninth mapping's value- Returns:
- a
Map
containing the specified mappings - Throws:
IllegalArgumentException
- if the values contain duplicate keysNullPointerException
- if any value isnull
-
of
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Map<K,V> of(V v1, V v2, V v3, V v4, V v5, V v6, V v7, V v8, V v9, V v10)
Returns an unmodifiable map containing ten mappings. The resulting map is NOT guaranteed to retain iteration order of mappings.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
v1
- the first mapping's valuev2
- the second mapping's valuev3
- the third mapping's valuev4
- the fourth mapping's valuev5
- the fifth mapping's valuev6
- the sixth mapping's valuev7
- the seventh mapping's valuev8
- the eighth mapping's valuev9
- the ninth mapping's valuev10
- the ninth mapping's value- Returns:
- a
Map
containing the specified mappings - Throws:
IllegalArgumentException
- if the values contain duplicate keysNullPointerException
- if any value isnull
-
of
@SafeVarargs public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Map<K,V> of(V... values)
Returns an unmodifiable map containing given values. The resulting map is NOT guaranteed to retain iteration order of the input array.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
values
- values from which the map is populated- Returns:
- a
Map
containing the specified values - Throws:
IllegalArgumentException
- if there are any duplicate keys in the provided valuesNullPointerException
- if any value isnull
, or if thevalues
array isnull
-
of
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Map<K,V> of(Collection<V> values)
Returns an unmodifiable map containing given values. The resulting map is NOT guaranteed to retain iteration order of the input collection.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
values
- values from which the map is populated- Returns:
- a
Map
containing the specified values - Throws:
IllegalArgumentException
- if there are any duplicate keys in the provided valuesNullPointerException
- if any value isnull
, or if thevalues
array isnull
-
toMap
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Collector<V,?,? extends Map<K,V>> toMap()
Returns a collector which collects bindingIdentifiable
objects into an unmodifiable map. The resulting map is NOT guaranteed to retain iteration order of the stream it collects.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Returns:
- A collector that accumulates the input elements into an unmodifiable map.
-
builder
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull BindingMap.Builder<K,V> builder()
Create a builder on an unmodifiable map, which does not retain value insertion order. The builder will be pre-sized to hold 4 elements.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Returns:
- A
BindingMap.Builder
instance.
-
builder
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull BindingMap.Builder<K,V> builder(int expectedSize)
Create a builder on an unmodifiable map, which does not retain value insertion order. The builder will be pre-sized to hold specified number of elements.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
expectedSize
- Expected number of values in the resulting map- Returns:
- A
BindingMap.Builder
instance.
-
ordered
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Map<K,V> ordered(V v1, V v2)
Returns an unmodifiable map containing two mappings. The resulting map will retain iteration order of mappings.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
v1
- the first mapping's valuev2
- the second mapping's value- Returns:
- a
Map
containing the specified mappings - Throws:
IllegalArgumentException
- if the values contain duplicate keysNullPointerException
- if any value isnull
-
ordered
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Map<K,V> ordered(V v1, V v2, V v3)
Returns an unmodifiable map containing three mappings. The resulting map will retain iteration order of mappings.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
v1
- the first mapping's valuev2
- the second mapping's valuev3
- the third mapping's value- Returns:
- a
Map
containing the specified mappings - Throws:
IllegalArgumentException
- if the values contain duplicate keysNullPointerException
- if any value isnull
-
ordered
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Map<K,V> ordered(V v1, V v2, V v3, V v4)
Returns an unmodifiable map containing four mappings. The resulting map will retain iteration order of mappings.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
v1
- the first mapping's valuev2
- the second mapping's valuev3
- the third mapping's valuev4
- the fourth mapping's value- Returns:
- a
Map
containing the specified mappings - Throws:
IllegalArgumentException
- if the values contain duplicate keysNullPointerException
- if any value isnull
-
ordered
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Map<K,V> ordered(V v1, V v2, V v3, V v4, V v5)
Returns an unmodifiable map containing five mappings. The resulting map will retain iteration order of mappings.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
v1
- the first mapping's valuev2
- the second mapping's valuev3
- the third mapping's valuev4
- the fourth mapping's valuev5
- the fifth mapping's value- Returns:
- a
Map
containing the specified mappings - Throws:
IllegalArgumentException
- if the values contain duplicate keysNullPointerException
- if any value isnull
-
ordered
@SafeVarargs public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Map<K,V> ordered(V... values)
Returns an unmodifiable map containing given values. ResultingMap
will retain the iteration order of values.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
values
- values from which the map is populated- Returns:
- a
Map
containing the specified values - Throws:
IllegalArgumentException
- if there are any duplicate keys in the provided valuesNullPointerException
- if any value isnull
, or if thevalues
array isnull
-
ordered
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Map<K,V> ordered(Collection<V> values)
Returns an unmodifiable map containing given values. ResultingMap
will retain the iteration order of values.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
values
- values from which the map is populated- Returns:
- a
Map
containing the specified values - Throws:
IllegalArgumentException
- if there are any duplicate keys in the provided valuesNullPointerException
- if any value isnull
, or if thevalues
array isnull
-
toOrderedMap
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull Collector<V,?,? extends Map<K,V>> toOrderedMap()
Returns a collector which collects bindingIdentifiable
objects into an unmodifiable map. The resulting map will retain iteration order of the stream it collects.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Returns:
- A collector that accumulates the input elements into an unmodifiable map.
-
orderedBuilder
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull BindingMap.Builder<K,V> orderedBuilder()
Create a builder on an unmodifiable map, which retains value insertion order. The builder will be pre-sized to hold 4 elements.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Returns:
- A
BindingMap.Builder
instance.
-
orderedBuilder
public static <K extends Identifier<V>,V extends Identifiable<K>> @NonNull BindingMap.Builder<K,V> orderedBuilder(int expectedSize)
Create a builder on an unmodifiable map, which retains value insertion order. The builder will be pre-sized to hold specified number of elements.- Type Parameters:
K
- theMap
's key typeV
- theMap
's value type- Parameters:
expectedSize
- Expected number of values in the resulting map- Returns:
- A
BindingMap.Builder
instance.
-
-