Interface SetMultimap<K,V>

Type Parameters:
K - key type | 键类型
V - value type | 值类型
All Superinterfaces:
Multimap<K,V>
All Known Subinterfaces:
SortedSetMultimap<K,V>
All Known Implementing Classes:
TreeSetMultimap

public interface SetMultimap<K,V> extends Multimap<K,V>
SetMultimap - Set-based Multimap Interface SetMultimap - 基于集合的多值映射接口

A multimap that stores values in sets, not allowing duplicate key-value pairs.

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

Features | 主要功能:

  • No duplicate values per key - 每个键不允许重复值
  • Set semantics - 集合语义
  • Efficient contains check - 高效的包含检查

Usage Examples | 使用示例:

SetMultimap<String, Integer> multimap = MultimapBuilder.linkedHashKeys()
    .linkedHashSetValues()
    .build();

multimap.put("a", 1);
multimap.put("a", 2);
multimap.put("a", 1); // duplicate ignored

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

Performance | 性能特性:

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

Security | 安全性:

  • Thread-safe: No (interface, implementation-dependent) - 否(接口,取决于实现)
  • Null-safe: No - 否
Since:
JDK 25, opencode-base-collections V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • get

      Set<V> get(K key)
      Get the set of values for a key. 获取键对应的值集合。
      Specified by:
      get in interface Multimap<K,V>
      Parameters:
      key - the key | 键
      Returns:
      the set of values | 值集合
    • removeAll

      Set<V> removeAll(Object key)
      Remove all values for a key and return them as a set. 移除键的所有值并以集合形式返回。
      Specified by:
      removeAll in interface Multimap<K,V>
      Parameters:
      key - the key | 键
      Returns:
      the removed values | 被移除的值
    • replaceValues

      Set<V> replaceValues(K key, Iterable<? extends V> values)
      Replace all values for a key and return the old values as a set. 替换键的所有值并以集合形式返回旧值。
      Specified by:
      replaceValues in interface Multimap<K,V>
      Parameters:
      key - the key | 键
      values - the new values | 新值
      Returns:
      the old values | 旧值
    • entries

      Set<Map.Entry<K,V>> entries()
      Return all entries as a set. 以集合形式返回所有条目。
      Specified by:
      entries in interface Multimap<K,V>
      Returns:
      the entries set | 条目集合