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
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:
-
Field Summary
Fields inherited from class AbstractMultimap
map -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> HashSetMultimap <K, V> create()Create an empty HashSetMultimap.static <K,V> HashSetMultimap <K, V> create(int expectedKeys, int expectedValuesPerKey) Create an empty HashSetMultimap with expected sizes.static <K,V> HashSetMultimap <K, V> Create a HashSetMultimap from an existing multimap.protected Collection<V> Create a new collection for values.Get the set of values for a key.Methods inherited from class AbstractMultimap
asMap, clear, containsEntry, containsKey, containsValue, entries, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, remove, removeAll, replaceValues, size, toString, values
-
Method Details
-
create
Create an empty HashSetMultimap. 创建空 HashSetMultimap。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Returns:
- new HashSetMultimap | 新的 HashSetMultimap
-
create
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
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
Description copied from class:AbstractMultimapCreate a new collection for values. 为值创建新集合。- Specified by:
createCollectionin classAbstractMultimap<K,V> - Returns:
- new collection | 新集合
-
getSet
-