Class ImmutableSetMultimap<K,V>

java.lang.Object
cloud.opencode.base.collections.immutable.ImmutableMultimap<K,V>
cloud.opencode.base.collections.immutable.ImmutableSetMultimap<K,V>
Type Parameters:
K - key type | 键类型
V - value type | 值类型
All Implemented Interfaces:
Multimap<K,V>, Serializable

public final class ImmutableSetMultimap<K,V> extends ImmutableMultimap<K,V>
ImmutableSetMultimap - Immutable Set Multimap Implementation ImmutableSetMultimap - 不可变集合多值映射实现

A multimap that stores values in sets, not allowing duplicate values for the same key.

将值存储在集合中的多值映射,不允许同一键的重复值。

Features | 主要功能:

  • Immutable - 不可变
  • Thread-safe - 线程安全
  • No duplicate values per key - 每个键无重复值

Usage Examples | 使用示例:

ImmutableSetMultimap<String, Integer> multimap = ImmutableSetMultimap.<String, Integer>builder()
    .put("a", 1)
    .put("a", 2)
    .put("a", 1) // duplicate ignored
    .build();

ImmutableSet<Integer> values = multimap.get("a"); // [1, 2]

Performance | 性能特性:

  • get: O(1) - get: O(1)
  • containsKey: O(1) - containsKey: O(1)

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
  • Null-safe: Yes (nulls not allowed) - 空值安全: 是(不允许空值)
Since:
JDK 25, opencode-base-collections V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • of

      public static <K,V> ImmutableSetMultimap<K,V> of()
      Return an empty immutable set multimap. 返回空不可变集合多值映射。
      Type Parameters:
      K - key type | 键类型
      V - value type | 值类型
      Returns:
      empty immutable set multimap | 空不可变集合多值映射
    • of

      public static <K,V> ImmutableSetMultimap<K,V> of(K k1, V v1)
      Return an immutable set multimap with one entry. 返回包含一个条目的不可变集合多值映射。
      Type Parameters:
      K - key type | 键类型
      V - value type | 值类型
      Parameters:
      k1 - key | 键
      v1 - value | 值
      Returns:
      immutable set multimap | 不可变集合多值映射
    • of

      public static <K,V> ImmutableSetMultimap<K,V> of(K k1, V v1, K k2, V v2)
      Return an immutable set multimap with two entries. 返回包含两个条目的不可变集合多值映射。
      Type Parameters:
      K - key type | 键类型
      V - value type | 值类型
      Parameters:
      k1 - first key | 第一个键
      v1 - first value | 第一个值
      k2 - second key | 第二个键
      v2 - second value | 第二个值
      Returns:
      immutable set multimap | 不可变集合多值映射
    • copyOf

      public static <K,V> ImmutableSetMultimap<K,V> copyOf(Multimap<? extends K, ? extends V> multimap)
      Copy from a multimap. 从多值映射复制。
      Type Parameters:
      K - key type | 键类型
      V - value type | 值类型
      Parameters:
      multimap - the multimap | 多值映射
      Returns:
      immutable set multimap | 不可变集合多值映射
    • builder

      public static <K,V> ImmutableSetMultimap.Builder<K,V> builder()
      Create a builder. 创建构建器。
      Type Parameters:
      K - key type | 键类型
      V - value type | 值类型
      Returns:
      builder | 构建器
    • get

      public ImmutableSet<V> get(K key)
      Description copied from interface: Multimap
      Return the collection of values for the key. 返回键的值集合。
      Specified by:
      get in interface Multimap<K,V>
      Specified by:
      get in class ImmutableMultimap<K,V>
      Parameters:
      key - the key | 键
      Returns:
      values collection (never null, may be empty) | 值集合(不为 null,可能为空)
    • asMap

      public Map<K, ? extends Collection<V>> asMap()
      Description copied from interface: Multimap
      Return a map view with key to collection mapping. 返回键到集合映射的视图。
      Specified by:
      asMap in interface Multimap<K,V>
      Specified by:
      asMap in class ImmutableMultimap<K,V>
      Returns:
      map view | 映射视图
    • inverse

      public ImmutableSetMultimap<V,K> inverse()
      Return the inverse multimap. 返回逆多值映射。
      Returns:
      inverse multimap | 逆多值映射