Interface SortedSetMultimap<K,V>
- Type Parameters:
K- key type | 键类型V- value type (must be Comparable or use custom Comparator) | 值类型(必须是 Comparable 或使用自定义 Comparator)
- All Superinterfaces:
Multimap<K,V>, SetMultimap<K, V>
- All Known Implementing Classes:
TreeSetMultimap
SortedSetMultimap - Multimap with Sorted Set Values
SortedSetMultimap - 具有排序集合值的多重映射
A SetMultimap whose values for each key are stored in a SortedSet, maintaining elements in sorted order.
一种 SetMultimap,其每个键的值存储在 SortedSet 中,保持元素的排序顺序。
Features | 主要功能:
- Sorted values per key - 每个键的值有序
- No duplicate values - 无重复值
- Natural or custom ordering - 自然排序或自定义排序
- Subset views - 子集视图
Usage Examples | 使用示例:
// Create with natural ordering
SortedSetMultimap<String, Integer> multimap = TreeSetMultimap.create();
// Create with custom comparator
SortedSetMultimap<String, String> customMap = TreeSetMultimap.create(
String.CASE_INSENSITIVE_ORDER);
// Add values
multimap.put("numbers", 3);
multimap.put("numbers", 1);
multimap.put("numbers", 2);
// Values are automatically sorted
SortedSet<Integer> values = multimap.get("numbers"); // [1, 2, 3]
// Get first/last
Integer first = multimap.get("numbers").first(); // 1
Integer last = multimap.get("numbers").last(); // 3
// Subset views
SortedSet<Integer> headSet = multimap.get("numbers").headSet(2); // [1]
SortedSet<Integer> tailSet = multimap.get("numbers").tailSet(2); // [2, 3]
Performance | 性能特性:
- get: O(1) for key lookup, O(log n) for set operations - get: O(1) 键查找,O(log n) 集合操作
- put: O(log n) per value - put: 每个值 O(log n)
- contains: O(log n) - contains: O(log n)
- first/last: O(log n) - first/last: O(log n)
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 Summary
Modifier and TypeMethodDescriptionReturns a map view where each key maps to a SortedSet of values.Get the sorted set of values for a key.Remove all values for a key and return them as a sorted set.replaceValues(K key, Iterable<? extends V> values) Replace all values for a key and return the old values as a sorted set.Comparator<? super V> Returns the comparator used to order values in each key's collection.Methods inherited from interface Multimap
asMap, clear, containsEntry, containsKey, containsValue, isEmpty, keys, keySet, put, putAll, putAll, putAll, remove, size, valuesMethods inherited from interface SetMultimap
entries
-
Method Details
-
get
-
removeAll
Remove all values for a key and return them as a sorted set. 移除键的所有值并以排序集合形式返回。 -
replaceValues
Replace all values for a key and return the old values as a sorted set. 替换键的所有值并以排序集合形式返回旧值。- Specified by:
replaceValuesin interfaceMultimap<K,V> - Specified by:
replaceValuesin interfaceSetMultimap<K,V> - Parameters:
key- the key | 键values- the new values | 新值- Returns:
- the old values as a sorted set | 以排序集合形式返回旧值
-
valueComparator
Comparator<? super V> valueComparator()Returns the comparator used to order values in each key's collection. 返回用于对每个键的集合中的值进行排序的比较器。Returns null if natural ordering is used.
如果使用自然排序则返回 null。
- Returns:
- the comparator, or null if natural ordering | 比较器,如果使用自然排序则为 null
-
asMapOfSortedSets
Returns a map view where each key maps to a SortedSet of values. 返回每个键映射到值的 SortedSet 的映射视图。Unlike the standard
asMap(), this method returns a map with SortedSet values, preserving the sorted nature of the values.与标准的
asMap()不同,此方法返回具有 SortedSet 值的映射, 保留值的排序特性。- Returns:
- the map view with SortedSet values | 具有 SortedSet 值的映射视图
-