Class ImmutableSortedMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
cloud.opencode.base.collections.immutable.ImmutableSortedMap<K,V>
- Type Parameters:
K- key type | 键类型V- value type | 值类型
- All Implemented Interfaces:
Serializable, Map<K,V>, NavigableMap<K, V>, SequencedMap<K, V>, SortedMap<K, V>
public final class ImmutableSortedMap<K,V>
extends AbstractMap<K,V>
implements NavigableMap<K,V>, Serializable
ImmutableSortedMap - Immutable Sorted Map Implementation
ImmutableSortedMap - 不可变有序映射实现
A sorted map that cannot be modified after creation. Entries are stored in sorted order by key.
创建后不能修改的有序映射。条目按键排序存储。
Features | 主要功能:
- Immutable - 不可变
- Thread-safe - 线程安全
- Sorted by key - 按键排序
- NavigableMap operations - NavigableMap 操作
Usage Examples | 使用示例:
// Create from entries - 从条目创建
ImmutableSortedMap<String, Integer> map = ImmutableSortedMap.of("c", 3, "a", 1, "b", 2);
// Keys in order: [a, b, c]
// Create with builder - 使用构建器创建
ImmutableSortedMap<String, Integer> map = ImmutableSortedMap.<String, Integer>naturalOrder()
.put("c", 3)
.put("a", 1)
.build();
Performance | 性能特性:
- get: O(log n) - get: O(log n)
- containsKey: O(log n) - containsKey: O(log n)
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for ImmutableSortedMap.Nested classes/interfaces inherited from class AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Method Summary
Modifier and TypeMethodDescriptionceilingEntry(K key) ceilingKey(K key) Comparator<? super K> booleancontainsKey(Object key) static <K extends Comparable<? super K>, V>
ImmutableSortedMap<K, V> Copy from a map.static <K,V> ImmutableSortedMap <K, V> copyOf(Map<? extends K, ? extends V> map, Comparator<? super K> comparator) Copy from a map with comparator.entrySet()firstKey()floorEntry(K key) higherEntry(K key) booleanisEmpty()lastKey()lowerEntry(K key) static <K extends Comparable<? super K>, V>
ImmutableSortedMap.Builder<K, V> Create a builder with natural ordering.static <K extends Comparable<? super K>, V>
ImmutableSortedMap<K, V> of()Return an empty immutable sorted map.static <K extends Comparable<? super K>, V>
ImmutableSortedMap<K, V> of(K k1, V v1) Return an immutable sorted map with one entry.static <K extends Comparable<? super K>, V>
ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2) Return an immutable sorted map with two entries.static <K extends Comparable<? super K>, V>
ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) Return an immutable sorted map with three entries.static <K,V> ImmutableSortedMap.Builder <K, V> orderedBy(Comparator<? super K> comparator) Create a builder with specified comparator.intsize()Methods inherited from class AbstractMap
clear, clone, containsValue, equals, hashCode, keySet, put, putAll, remove, toString, valuesMethods inherited from interface Map
clear, compute, computeIfAbsent, computeIfPresent, containsValue, equals, forEach, getOrDefault, hashCode, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAllMethods inherited from interface NavigableMap
reversedMethods inherited from interface SequencedMap
sequencedEntrySet, sequencedKeySet, sequencedValues
-
Method Details
-
of
Return an empty immutable sorted map. 返回空不可变有序映射。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Returns:
- empty immutable sorted map | 空不可变有序映射
-
of
Return an immutable sorted map with one entry. 返回包含一个条目的不可变有序映射。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
k1- key | 键v1- value | 值- Returns:
- immutable sorted map | 不可变有序映射
-
of
public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K,V> of(K k1, V v1, K k2, V v2) Return an immutable sorted map with two entries. 返回包含两个条目的不可变有序映射。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
k1- first key | 第一个键v1- first value | 第一个值k2- second key | 第二个键v2- second value | 第二个值- Returns:
- immutable sorted map | 不可变有序映射
-
of
public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3) Return an immutable sorted map with three entries. 返回包含三个条目的不可变有序映射。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
k1- first key | 第一个键v1- first value | 第一个值k2- second key | 第二个键v2- second value | 第二个值k3- third key | 第三个键v3- third value | 第三个值- Returns:
- immutable sorted map | 不可变有序映射
-
copyOf
public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K,V> copyOf(Map<? extends K, ? extends V> map) Copy from a map. 从映射复制。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
map- the map | 映射- Returns:
- immutable sorted map | 不可变有序映射
-
copyOf
public static <K,V> ImmutableSortedMap<K,V> copyOf(Map<? extends K, ? extends V> map, Comparator<? super K> comparator) Copy from a map with comparator. 使用比较器从映射复制。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
map- the map | 映射comparator- the comparator | 比较器- Returns:
- immutable sorted map | 不可变有序映射
-
naturalOrder
Create a builder with natural ordering. 创建使用自然顺序的构建器。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Returns:
- builder | 构建器
-
orderedBy
Create a builder with specified comparator. 创建使用指定比较器的构建器。- Type Parameters:
K- key type | 键类型V- value type | 值类型- Parameters:
comparator- the comparator | 比较器- Returns:
- builder | 构建器
-
size
-
isEmpty
-
containsKey
- Specified by:
containsKeyin interfaceMap<K,V> - Overrides:
containsKeyin classAbstractMap<K,V>
-
get
-
entrySet
-
comparator
- Specified by:
comparatorin interfaceSortedMap<K,V>
-
firstKey
-
lastKey
-
lowerEntry
- Specified by:
lowerEntryin interfaceNavigableMap<K,V>
-
lowerKey
-
floorEntry
- Specified by:
floorEntryin interfaceNavigableMap<K,V>
-
floorKey
-
ceilingEntry
- Specified by:
ceilingEntryin interfaceNavigableMap<K,V>
-
ceilingKey
- Specified by:
ceilingKeyin interfaceNavigableMap<K,V>
-
higherEntry
- Specified by:
higherEntryin interfaceNavigableMap<K,V>
-
higherKey
-
firstEntry
- Specified by:
firstEntryin interfaceNavigableMap<K,V> - Specified by:
firstEntryin interfaceSequencedMap<K,V>
-
lastEntry
-
pollFirstEntry
- Specified by:
pollFirstEntryin interfaceNavigableMap<K,V> - Specified by:
pollFirstEntryin interfaceSequencedMap<K,V>
-
pollLastEntry
- Specified by:
pollLastEntryin interfaceNavigableMap<K,V> - Specified by:
pollLastEntryin interfaceSequencedMap<K,V>
-
descendingMap
- Specified by:
descendingMapin interfaceNavigableMap<K,V>
-
descendingKeySet
- Specified by:
descendingKeySetin interfaceNavigableMap<K,V>
-
subMap
- Specified by:
subMapin interfaceNavigableMap<K,V>
-
headMap
- Specified by:
headMapin interfaceNavigableMap<K,V>
-
tailMap
- Specified by:
tailMapin interfaceNavigableMap<K,V>
-
subMap
-
headMap
-
tailMap
-