Class MapBuilder<K,V>

java.lang.Object
io.vertigo.core.lang.MapBuilder<K,V>
Type Parameters:
K - Type of keys
V - Type of mapped values
All Implemented Interfaces:
Builder<Map<K,V>>

public final class MapBuilder<K,V> extends Object implements Builder<Map<K,V>>
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 Details

    • MapBuilder

      public MapBuilder()
  • Method Details

    • putCheckKeyNotExists

      public MapBuilder<K,V> putCheckKeyNotExists(K key, V value)
      Adds a key-value pair with duplicate key check. Ensures no existing value for the key.
      Parameters:
      key - Key to add
      value - Non-null value to associate
      Returns:
      Current builder for chaining
      Throws:
      IllegalArgumentException - if key already exists
    • putAll

      public MapBuilder<K,V> putAll(Map<K,V> map)
      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

      public MapBuilder<K,V> put(K key, V value)
      Adds a required key-value pair. Both key and value must be non-null.
      Parameters:
      key - Key to add
      value - Non-null value to associate
      Returns:
      Current builder for chaining
    • putNullable

      public MapBuilder<K,V> putNullable(K key, V value)
      Adds an optional key-value pair. Only adds if value is non-null.
      Parameters:
      key - Key to add
      value - Value to associate (may be null)
      Returns:
      Current builder for chaining
    • unmodifiable

      public MapBuilder<K,V> unmodifiable()
      Makes the resulting map unmodifiable. Creates defensive copy on build.
      Returns:
      Current builder for chaining
    • build

      public Map<K,V> build()
      Creates the final map. Returns unmodifiable copy if requested.
      Specified by:
      build in interface Builder<K>
      Returns:
      Built map instance