Class HashSetMultimap<K,V>

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

public class HashSetMultimap<K,V> extends AbstractMultimap<K,V>
HashSetMultimap - Set-based Multimap Implementation HashSetMultimap - 基于集合的多重映射实现

A Multimap implementation that uses HashSet for each key's values. Duplicate values per key are not allowed.

使用 HashSet 存储每个键的值的 Multimap 实现。不允许每个键有重复值。

Features | 主要功能:

  • No duplicate values per key - 每个键无重复值
  • O(1) contains check - O(1) 包含检查
  • O(1) put operations - O(1) 放入操作
  • Serializable - 可序列化

Usage Examples | 使用示例:

// Create empty - 创建空
HashSetMultimap<String, Integer> multimap = HashSetMultimap.create();

// Create with capacity - 创建指定容量
HashSetMultimap<String, Integer> multimap = HashSetMultimap.create(16, 4);

// Create from existing - 从现有创建
HashSetMultimap<String, Integer> multimap = HashSetMultimap.create(existingMultimap);

// Operations - 操作
multimap.put("a", 1);
multimap.put("a", 2);
multimap.put("a", 1);  // ignored (duplicate)
Set<Integer> values = (Set<Integer>) multimap.get("a");  // [1, 2]

Performance | 性能特性:

  • put: O(1) average - put: O(1) 平均
  • get: O(1) - get: O(1)
  • remove: O(1) average - remove: O(1) 平均
  • containsEntry: O(1) average - containsEntry: O(1) 平均

Security | 安全性:

  • Thread-safe: No - 线程安全: 否
  • Null-safe: Yes (allows null keys and values) - 空值安全: 是(允许空键和值)
Since:
JDK 25, opencode-base-collections V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • create

      public static <K,V> HashSetMultimap<K,V> create()
      Create an empty HashSetMultimap. 创建空 HashSetMultimap。
      Type Parameters:
      K - key type | 键类型
      V - value type | 值类型
      Returns:
      new HashSetMultimap | 新的 HashSetMultimap
    • create

      public static <K,V> HashSetMultimap<K,V> create(int expectedKeys, int expectedValuesPerKey)
      Create an empty HashSetMultimap with expected sizes. 创建指定预期大小的空 HashSetMultimap。
      Type Parameters:
      K - key type | 键类型
      V - value type | 值类型
      Parameters:
      expectedKeys - expected number of keys | 预期键数量
      expectedValuesPerKey - expected values per key | 预期每键值数量
      Returns:
      new HashSetMultimap | 新的 HashSetMultimap
    • create

      public static <K,V> HashSetMultimap<K,V> create(Multimap<? extends K, ? extends V> multimap)
      Create a HashSetMultimap from an existing multimap. 从现有多重映射创建 HashSetMultimap。
      Type Parameters:
      K - key type | 键类型
      V - value type | 值类型
      Parameters:
      multimap - source multimap | 源多重映射
      Returns:
      new HashSetMultimap | 新的 HashSetMultimap
    • createCollection

      protected Collection<V> createCollection()
      Description copied from class: AbstractMultimap
      Create a new collection for values. 为值创建新集合。
      Specified by:
      createCollection in class AbstractMultimap<K,V>
      Returns:
      new collection | 新集合
    • getSet

      public Set<V> getSet(K key)
      Get the set of values for a key. 获取键的值集合。
      Parameters:
      key - the key | 键
      Returns:
      values set | 值集合