Class ImmutableRangeMap<K extends Comparable<? super K>, V>
java.lang.Object
cloud.opencode.base.collections.immutable.ImmutableRangeMap<K,V>
- Type Parameters:
K- the type of range endpoints | 范围端点类型V- the type of values | 值类型
- All Implemented Interfaces:
RangeMap<K,V>, Serializable
public final class ImmutableRangeMap<K extends Comparable<? super K>, V>
extends Object
implements RangeMap<K,V>, Serializable
ImmutableRangeMap - Immutable Range Map
ImmutableRangeMap - 不可变范围映射
An immutable implementation of RangeMap that maps disjoint non-empty
ranges to values. All mutation methods throw UnsupportedOperationException.
RangeMap 的不可变实现,将不相交的非空范围映射到值。
所有变更方法抛出 UnsupportedOperationException。
Features | 主要功能:
- Immutable & thread-safe - 不可变且线程安全
- Binary search for efficient key lookup - 二分搜索实现高效键查找
- Builder pattern using
TreeRangeMapfor range management - 使用 TreeRangeMap 管理范围的构建器模式
Usage Examples | 使用示例:
// Create via builder - 通过构建器创建
ImmutableRangeMap<Integer, String> rangeMap = ImmutableRangeMap.<Integer, String>builder()
.put(Range.closed(1, 10), "small")
.put(Range.closed(11, 100), "medium")
.put(Range.closed(101, 1000), "large")
.build();
// Query - 查询
String value = rangeMap.get(5); // "small"
String value2 = rangeMap.get(50); // "medium"
// Get entry - 获取条目
Map.Entry<Range<Integer>, String> entry = rangeMap.getEntry(5);
// entry.getKey() = [1, 10], entry.getValue() = "small"
Performance | 性能特性:
- get / getEntry: O(log n) via binary search - O(log n) 通过二分搜索
- asMapOfRanges: O(n) - O(n)
- subRangeMap: O(n) - O(n)
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Null-safe: No (keys and values must not be null) - 空值安全: 否(键和值不能为null)
- Since:
- JDK 25, opencode-base-collections V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classImmutableRangeMap.Builder<K extends Comparable<? super K>, V>Builder forImmutableRangeMap. -
Method Summary
Modifier and TypeMethodDescriptionReturn all range-value mappings in descending order.Return all range-value mappings as a map.static <K extends Comparable<? super K>, V>
ImmutableRangeMap.Builder<K, V> builder()Create a new builder forImmutableRangeMap.voidclear()Not supported.static <K extends Comparable<? super K>, V>
ImmutableRangeMap<K, V> Create an immutable range map by copying from aRangeMap.booleanGet the value associated with the key.Get the entry (range and value) containing the key.inthashCode()booleanisEmpty()Check if this range map is empty.static <K extends Comparable<? super K>, V>
ImmutableRangeMap<K, V> of()Create an empty immutable range map.static <K extends Comparable<? super K>, V>
ImmutableRangeMap<K, V> Create an immutable range map with a single range-value mapping.voidNot supported.voidNot supported.voidputCoalescing(Range<K> range, V value) Not supported.voidNot supported.span()Return the minimal range that encloses all ranges in this map.subRangeMap(Range<K> range) Return a view of the portion of this map within the given range.toString()
-
Method Details
-
of
Create an empty immutable range map. 创建空的不可变范围映射。- Type Parameters:
K- endpoint type | 端点类型V- value type | 值类型- Returns:
- empty immutable range map | 空的不可变范围映射
-
of
public static <K extends Comparable<? super K>, V> ImmutableRangeMap<K,V> of(Range<K> range, V value) Create an immutable range map with a single range-value mapping. 创建包含单个范围-值映射的不可变范围映射。- Type Parameters:
K- endpoint type | 端点类型V- value type | 值类型- Parameters:
range- the range | 范围value- the value | 值- Returns:
- immutable range map | 不可变范围映射
-
copyOf
public static <K extends Comparable<? super K>, V> ImmutableRangeMap<K,V> copyOf(RangeMap<K, V> rangeMap) - Type Parameters:
K- endpoint type | 端点类型V- value type | 值类型- Parameters:
rangeMap- the range map to copy | 要复制的范围映射- Returns:
- immutable range map | 不可变范围映射
-
builder
Create a new builder forImmutableRangeMap. 创建ImmutableRangeMap的新构建器。- Type Parameters:
K- endpoint type | 端点类型V- value type | 值类型- Returns:
- new builder | 新构建器
-
get
-
getEntry
Description copied from interface:RangeMapGet the entry (range and value) containing the key. 获取包含键的条目(范围和值)。 -
span
-
isEmpty
-
asMapOfRanges
-
asDescendingMapOfRanges
-
subRangeMap
Description copied from interface:RangeMapReturn a view of the portion of this map within the given range. 返回此映射在给定范围内的部分的视图。- Specified by:
subRangeMapin interfaceRangeMap<K extends Comparable<? super K>, V>- Parameters:
range- the range | 范围- Returns:
- the sub range map | 子范围映射
-
put
Not supported. Always throwsUnsupportedOperationException. 不支持。始终抛出UnsupportedOperationException。- Specified by:
putin interfaceRangeMap<K extends Comparable<? super K>, V>- Parameters:
range- the range | 范围value- the value | 值- Throws:
UnsupportedOperationException- always | 始终抛出
-
putCoalescing
Not supported. Always throwsUnsupportedOperationException. 不支持。始终抛出UnsupportedOperationException。- Specified by:
putCoalescingin interfaceRangeMap<K extends Comparable<? super K>, V>- Parameters:
range- the range | 范围value- the value | 值- Throws:
UnsupportedOperationException- always | 始终抛出
-
putAll
Not supported. Always throwsUnsupportedOperationException. 不支持。始终抛出UnsupportedOperationException。- Specified by:
putAllin interfaceRangeMap<K extends Comparable<? super K>, V>- Parameters:
rangeMap- the range map | 范围映射- Throws:
UnsupportedOperationException- always | 始终抛出
-
remove
Not supported. Always throwsUnsupportedOperationException. 不支持。始终抛出UnsupportedOperationException。- Specified by:
removein interfaceRangeMap<K extends Comparable<? super K>, V>- Parameters:
range- the range | 范围- Throws:
UnsupportedOperationException- always | 始终抛出
-
clear
public void clear()Not supported. Always throwsUnsupportedOperationException. 不支持。始终抛出UnsupportedOperationException。- Specified by:
clearin interfaceRangeMap<K extends Comparable<? super K>, V>- Throws:
UnsupportedOperationException- always | 始终抛出
-
equals
-
hashCode
-
toString
-