Class ImmutableListMultimap<K,V>

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

public final class ImmutableListMultimap<K,V> extends ImmutableMultimap<K,V>
ImmutableListMultimap - Immutable List Multimap Implementation ImmutableListMultimap - 不可变列表多值映射实现

A multimap that stores values in lists, preserving insertion order and allowing duplicates.

将值存储在列表中的多值映射,保留插入顺序并允许重复。

Features | 主要功能:

  • Immutable - 不可变
  • Thread-safe - 线程安全
  • Preserves insertion order - 保留插入顺序
  • Allows duplicate values - 允许重复值

Usage Examples | 使用示例:

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

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

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> ImmutableListMultimap<K,V> of()
      Return an empty immutable list multimap. 返回空不可变列表多值映射。
      Type Parameters:
      K - key type | 键类型
      V - value type | 值类型
      Returns:
      empty immutable list multimap | 空不可变列表多值映射
    • of

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

      public static <K,V> ImmutableListMultimap<K,V> of(K k1, V v1, K k2, V v2)
      Return an immutable list 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 list multimap | 不可变列表多值映射
    • copyOf

      public static <K,V> ImmutableListMultimap<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 list multimap | 不可变列表多值映射
    • builder

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

      public ImmutableList<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 ImmutableListMultimap<V,K> inverse()
      Return the inverse multimap. 返回逆多值映射。
      Returns:
      inverse multimap | 逆多值映射