Class ImmutableMultimap<K,V>
java.lang.Object
cloud.opencode.base.collections.immutable.ImmutableMultimap<K,V>
- Type Parameters:
K- key type | 键类型V- value type | 值类型
- All Implemented Interfaces:
Multimap<K,V>, Serializable
- Direct Known Subclasses:
ImmutableListMultimap, ImmutableSetMultimap
ImmutableMultimap - Immutable Multimap Implementation
ImmutableMultimap - 不可变多值映射实现
A multimap that cannot be modified after creation. Each key can map to multiple values.
创建后不能修改的多值映射。每个键可以映射到多个值。
Features | 主要功能:
- Immutable - 不可变
- Thread-safe - 线程安全
- Multiple values per key - 每个键多个值
Usage Examples | 使用示例:
// Create using builder - 使用构建器创建
ImmutableMultimap<String, Integer> multimap = ImmutableMultimap.<String, Integer>builder()
.put("a", 1)
.put("a", 2)
.put("b", 3)
.build();
Collection<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 Summary
Modifier and TypeMethodDescriptionabstract Map<K, ? extends Collection<V>> asMap()Return a map view with key to collection mapping.voidclear()Clear all entries.booleancontainsEntry(Object key, Object value) Check if the multimap contains the key-value pair.booleancontainsKey(Object key) Check if the multimap contains the key.booleancontainsValue(Object value) Check if the multimap contains the value.static <K,V> ImmutableMultimap <K, V> Copy from a multimap.entries()Return a collection view of all key-value pairs.abstract Collection<V> Return the collection of values for the key.booleanisEmpty()Check if the multimap is empty.keys()Return a multiset view of the keys (includes duplicates by value count).keySet()Return a set view of the keys.booleanStore a key-value pair.voidStore all key-value pairs from another multimap.booleanStore multiple values for a key.booleanRemove a single key-value pair.Remove all values for a key.replaceValues(K key, Iterable<? extends V> values) Replace all values for a key.intsize()Return the total number of key-value pairs.values()Return a collection view of all values.
-
Method Details
-
copyOf
Copy from a multimap. 从多值映射复制。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
multimap- the multimap | 多值映射- Returns:
- immutable multimap | 不可变多值映射
-
size
-
isEmpty
-
containsKey
-
containsValue
-
containsEntry
Description copied from interface:MultimapCheck if the multimap contains the key-value pair. 检查多重映射是否包含键值对。- Specified by:
containsEntryin interfaceMultimap<K,V> - Parameters:
key- the key | 键value- the value | 值- Returns:
- true if contains | 如果包含则返回 true
-
get
-
keySet
-
keys
-
values
-
entries
-
asMap
-
put
-
remove
-
putAll
-
putAll
-
replaceValues
Description copied from interface:MultimapReplace all values for a key. 替换键的所有值。- Specified by:
replaceValuesin interfaceMultimap<K,V> - Parameters:
key- the key | 键values- the new values | 新值- Returns:
- previous values | 之前的值
-
removeAll
-
clear
-