Class MapBuilder<K,​V>

  • Type Parameters:
    K - the type of keys
    V - the type of mapped values
    All Implemented Interfaces:
    Builder<Map<K,​V>>

    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 Detail

      • MapBuilder

        public MapBuilder()
    • 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 - Key
        value - 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 - Key
        value - Value not null
        Returns:
        this builder
      • putNullable

        public MapBuilder<K,​V> putNullable​(K key,
                                                 V value)
        Adds nullable key-value.
        Parameters:
        key - Key
        value - Value nullable
        Returns:
        this builder
      • unmodifiable

        public MapBuilder<K,​V> unmodifiable()
        Makes this map as unmodifiable.
        Returns:
        this builder
      • build

        public Map<K,​V> build()
        Specified by:
        build in interface Builder<K>
        Returns:
        the built object