Package software.amazon.awssdk.utils
Class ImmutableMap.Builder<K,V>
- java.lang.Object
-
- software.amazon.awssdk.utils.ImmutableMap.Builder<K,V>
-
- Enclosing class:
- ImmutableMap<K,V>
public static class ImmutableMap.Builder<K,V> extends Object
A convenient builder for creating ImmutableMap instances.
-
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ImmutableMap.Builder<K,V>allowDuplicateKeys(boolean allowDuplicateKeys)Sets whether duplicate keys are allowed.ImmutableMap<K,V>build()Generates and returns a new ImmutableMap instance which contains all the entries added into the Builder byput()method.ImmutableMap.Builder<K,V>put(K key, V value)Add a key-value pair into the built map.
-
-
-
Method Detail
-
put
public ImmutableMap.Builder<K,V> put(K key, V value)
Add a key-value pair into the built map. The method will throw IllegalArgumentException immediately when duplicate keys are provided and allowDuplicateKeys is false (default value). If duplicate keys are provided and allowDuplicateKeys is true, the latest value will overwrite the existing value, and the SDK will log a message at WARN level.- Returns:
- Returns a reference to this object so that method calls can be chained together.
-
allowDuplicateKeys
public ImmutableMap.Builder<K,V> allowDuplicateKeys(boolean allowDuplicateKeys)
Sets whether duplicate keys are allowed. If true, the latest value will overwrite the existing value. If false, an error will be thrown when attempting to put an entry with a duplicate key. Default value is false.- Returns:
- Returns a reference to this object so that method calls can be chained together.
-
build
public ImmutableMap<K,V> build()
Generates and returns a new ImmutableMap instance which contains all the entries added into the Builder byput()method.
-
-