Package io.vertigo.core.lang
Class MapBuilder<K,V>
java.lang.Object
io.vertigo.core.lang.MapBuilder<K,V>
- Type Parameters:
K- Type of keysV- Type of mapped values
Fluent builder for Map construction.
Provides type-safe map creation with various put operations and validation:
- Required values (put)
- Optional values (putNullable)
- Duplicate key check (putCheckKeyNotExists)
- Bulk insertion (putAll)
Can create immutable maps using unmodifiable().
- Author:
- pchretien
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Creates the final map.MapBuilder<K, V> Adds a required key-value pair.MapBuilder<K, V> Adds all entries from another map.MapBuilder<K, V> putCheckKeyNotExists(K key, V value) Adds a key-value pair with duplicate key check.MapBuilder<K, V> putNullable(K key, V value) Adds an optional key-value pair.MapBuilder<K, V> Makes the resulting map unmodifiable.
-
Constructor Details
-
MapBuilder
public MapBuilder()
-
-
Method Details
-
putCheckKeyNotExists
Adds a key-value pair with duplicate key check. Ensures no existing value for the key.- Parameters:
key- Key to addvalue- Non-null value to associate- Returns:
- Current builder for chaining
- Throws:
IllegalArgumentException- if key already exists
-
putAll
Adds all entries from another map. All values must be non-null.- Parameters:
map- Source map to copy from- Returns:
- Current builder for chaining
-
put
Adds a required key-value pair. Both key and value must be non-null.- Parameters:
key- Key to addvalue- Non-null value to associate- Returns:
- Current builder for chaining
-
putNullable
Adds an optional key-value pair. Only adds if value is non-null.- Parameters:
key- Key to addvalue- Value to associate (may be null)- Returns:
- Current builder for chaining
-
unmodifiable
Makes the resulting map unmodifiable. Creates defensive copy on build.- Returns:
- Current builder for chaining
-
build
Creates the final map. Returns unmodifiable copy if requested.
-