Package io.vertigo.core.util
Class MapBuilder<K,V>
- java.lang.Object
-
- io.vertigo.core.util.MapBuilder<K,V>
-
- Type Parameters:
K
- the type of keysV
- the type of mapped values
public final class MapBuilder<K,V> extends Object implements Builder<Map<K,V>>
The MapBuilder class allows to build a map. The map can be immutable using unmodifiable(). Several put() methods exist to cover the frequent cases.- Author:
- pchretien
-
-
Constructor Summary
Constructors Constructor Description MapBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<K,V>
build()
MapBuilder<K,V>
put(K key, V value)
Adds key-value.MapBuilder<K,V>
putAll(Map<K,V> map)
Adds a map of key-value.MapBuilder<K,V>
putCheckKeyNotExists(K key, V value)
Adds key-value.MapBuilder<K,V>
putNullable(K key, V value)
Adds nullable key-value.MapBuilder<K,V>
unmodifiable()
Makes this map as unmodifiable.
-
-
-
Method Detail
-
putCheckKeyNotExists
public MapBuilder<K,V> putCheckKeyNotExists(K key, V value)
Adds key-value. If the same value exists then an exception is thrown.- Parameters:
key
- Keyvalue
- Value not null- Returns:
- this builder
-
putAll
public MapBuilder<K,V> putAll(Map<K,V> map)
Adds a map of key-value. Values are required.- Parameters:
map
- Map- Returns:
- this builder
-
put
public MapBuilder<K,V> put(K key, V value)
Adds key-value. The value is required.- Parameters:
key
- Keyvalue
- Value not null- Returns:
- this builder
-
putNullable
public MapBuilder<K,V> putNullable(K key, V value)
Adds nullable key-value.- Parameters:
key
- Keyvalue
- Value nullable- Returns:
- this builder
-
unmodifiable
public MapBuilder<K,V> unmodifiable()
Makes this map as unmodifiable.- Returns:
- this builder
-
-