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 TreeRangeMap for 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:
  • Method Details