Class OpenCollections.MapBuilder<K,V>

java.lang.Object
cloud.opencode.base.core.collect.OpenCollections.MapBuilder<K,V>
Type Parameters:
K - the key type / 键类型
V - the value type / 值类型
Enclosing class:
OpenCollections

public static final class OpenCollections.MapBuilder<K,V> extends Object
A builder for creating unmodifiable maps incrementally. 用于增量创建不可修改映射的构建器。
Since:
JDK 25, opencode-base-core V1.0.3
Author:
Leon Soo www.LeonSoo.com
  • Method Details

    • put

      public OpenCollections.MapBuilder<K,V> put(K key, V value)
      Puts a key-value pair into this builder. 向此构建器添加键值对。
      Parameters:
      key - the key (must not be null) / 键(不可为 null)
      value - the value (must not be null) / 值(不可为 null)
      Returns:
      this builder / 此构建器
      Throws:
      NullPointerException - if key or value is null / 如果 key 或 value 为 null
    • putAll

      public OpenCollections.MapBuilder<K,V> putAll(Map<? extends K, ? extends V> map)
      Puts all entries from the given map into this builder. 将给定映射的所有条目添加到此构建器。
      Parameters:
      map - the map whose entries to add (must not be null, no null keys or values) / 要添加条目的映射(不可为 null,键和值不可为 null)
      Returns:
      this builder / 此构建器
      Throws:
      NullPointerException - if map, any key, or any value is null / 如果 map、任何键或任何值为 null
    • build

      public Map<K,V> build()
      Builds and returns an unmodifiable map containing all added entries. 构建并返回包含所有已添加条目的不可修改映射。
      Returns:
      an unmodifiable map / 不可修改映射