Class ArrayListMultimap<K,V>
java.lang.Object
cloud.opencode.base.collections.AbstractMultimap<K,V>
cloud.opencode.base.collections.ArrayListMultimap<K,V>
- Type Parameters:
K- key type | 键类型V- value type | 值类型
- All Implemented Interfaces:
Multimap<K,V>, Serializable
ArrayListMultimap - List-based Multimap Implementation
ArrayListMultimap - 基于列表的多重映射实现
A Multimap implementation that uses ArrayList for each key's values. Values are stored in insertion order and duplicates are allowed.
使用 ArrayList 存储每个键的值的 Multimap 实现。值按插入顺序存储,允许重复。
Features | 主要功能:
- Preserves insertion order - 保留插入顺序
- Allows duplicate values - 允许重复值
- O(1) put operations - O(1) 放入操作
- Serializable - 可序列化
Usage Examples | 使用示例:
// Create empty - 创建空
ArrayListMultimap<String, Integer> multimap = ArrayListMultimap.create();
// Create with capacity - 创建指定容量
ArrayListMultimap<String, Integer> multimap = ArrayListMultimap.create(16, 4);
// Create from existing - 从现有创建
ArrayListMultimap<String, Integer> multimap = ArrayListMultimap.create(existingMultimap);
// Operations - 操作
multimap.put("a", 1);
multimap.put("a", 2);
multimap.put("a", 1); // duplicate allowed
List<Integer> values = (List<Integer>) multimap.get("a"); // [1, 2, 1]
Performance | 性能特性:
- put: O(1) amortized - put: O(1) 均摊
- get: O(1) - get: O(1)
- remove: O(n) for value in list - remove: O(n) 对于列表中的值
- containsEntry: O(n) - containsEntry: O(n)
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> ArrayListMultimap <K, V> create()Create an empty ArrayListMultimap.static <K,V> ArrayListMultimap <K, V> create(int expectedKeys, int expectedValuesPerKey) Create an empty ArrayListMultimap with expected sizes.static <K,V> ArrayListMultimap <K, V> Create an ArrayListMultimap from an existing multimap.protected Collection<V> Create a new collection for values.Get the list 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 ArrayListMultimap. 创建空 ArrayListMultimap。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Returns:
- new ArrayListMultimap | 新的 ArrayListMultimap
-
create
Create an empty ArrayListMultimap with expected sizes. 创建指定预期大小的空 ArrayListMultimap。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
expectedKeys- expected number of keys | 预期键数量expectedValuesPerKey- expected values per key | 预期每键值数量- Returns:
- new ArrayListMultimap | 新的 ArrayListMultimap
-
create
Create an ArrayListMultimap from an existing multimap. 从现有多重映射创建 ArrayListMultimap。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
multimap- source multimap | 源多重映射- Returns:
- new ArrayListMultimap | 新的 ArrayListMultimap
-
createCollection
Description copied from class:AbstractMultimapCreate a new collection for values. 为值创建新集合。- Specified by:
createCollectionin classAbstractMultimap<K,V> - Returns:
- new collection | 新集合
-
getList
-