Class MapBuilder<K,V>

java.lang.Object
com.google.cloud.spring.core.util.MapBuilder<K,V>
Type Parameters:
K - map key type
V - map value type

public final class MapBuilder<K,V> extends Object
Utility for building an immutable, type-safe Map.

Underlying implementation uses a HashMap, but disallows null keys, null values, and duplicate keys. This is consistent with Java 9 Map.of() static factory method, which will eventually replace the uses of this utility.

Since:
1.1
  • Constructor Details

    • MapBuilder

      public MapBuilder()
  • Method Details

    • put

      public MapBuilder<K,V> put(K key, V value)
      Adds a unique non-null key/value pair.
      Parameters:
      key - non-null key
      value - non-null value
      Returns:
      itself for chaining
    • build

      public Map<K,V> build()
    • buildModifiable

      public Map<K,V> buildModifiable()