Interface RangeMap<K extends Comparable<? super K>, V>

Type Parameters:
K - the type of range endpoints | 范围端点类型
V - the type of values | 值类型
All Known Implementing Classes:
ImmutableRangeMap, TreeRangeMap

public interface RangeMap<K extends Comparable<? super K>, V>
RangeMap - Range Map Interface RangeMap - 范围映射接口

A mapping from disjoint non-empty ranges to values.

从不相交的非空范围到值的映射。

Features | 主要功能:

  • Automatic range coalescing - 自动范围合并
  • Efficient range-based lookup - 高效的基于范围的查找
  • Range-value association - 范围-值关联

Usage Examples | 使用示例:

RangeMap<Integer, String> rangeMap = TreeRangeMap.create();
rangeMap.put(Range.closed(1, 10), "small");
rangeMap.put(Range.closed(11, 100), "medium");
rangeMap.put(Range.closed(101, 1000), "large");

String value = rangeMap.get(5);   // "small"
String value2 = rangeMap.get(50); // "medium"

Security | 安全性:

  • Thread-safe: No (interface, implementation-dependent) - 否(接口,取决于实现)
  • Null-safe: No (key must not be null) - 否(键不能为null)
Since:
JDK 25, opencode-base-collections V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Return all range-value mappings in descending order.
    Return all range-value mappings as a map.
    void
    Clear all mappings.
    get(K key)
    Get the value associated with the key.
    getEntry(K key)
    Get the entry (range and value) containing the key.
    boolean
    Check if this range map is empty.
    void
    put(Range<K> range, V value)
    Associate a range with a value.
    void
    putAll(RangeMap<K, ? extends V> rangeMap)
    Put all mappings from another range map.
    void
    putCoalescing(Range<K> range, V value)
    Associate a range with a value, coalescing with adjacent ranges with the same value.
    void
    remove(Range<K> range)
    Remove a range from this map.
    Return the minimal range that encloses all ranges in this map.
    Return a view of the portion of this map within the given range.
  • Method Details

    • get

      V get(K key)
      Get the value associated with the key. 获取与键关联的值。
      Parameters:
      key - the key | 键
      Returns:
      the value, or null if not found | 值,如果未找到则返回 null
    • getEntry

      Map.Entry<Range<K>,V> getEntry(K key)
      Get the entry (range and value) containing the key. 获取包含键的条目(范围和值)。
      Parameters:
      key - the key | 键
      Returns:
      the entry, or null if not found | 条目,如果未找到则返回 null
    • span

      Range<K> span()
      Return the minimal range that encloses all ranges in this map. 返回包含此映射中所有范围的最小范围。
      Returns:
      the span | 跨度
    • isEmpty

      boolean isEmpty()
      Check if this range map is empty. 检查此范围映射是否为空。
      Returns:
      true if empty | 如果为空则返回 true
    • asMapOfRanges

      Map<Range<K>,V> asMapOfRanges()
      Return all range-value mappings as a map. 以映射形式返回所有范围-值映射。
      Returns:
      the map | 映射
    • asDescendingMapOfRanges

      Map<Range<K>,V> asDescendingMapOfRanges()
      Return all range-value mappings in descending order. 以降序返回所有范围-值映射。
      Returns:
      the descending map | 降序映射
    • subRangeMap

      RangeMap<K,V> subRangeMap(Range<K> range)
      Return a view of the portion of this map within the given range. 返回此映射在给定范围内的部分的视图。
      Parameters:
      range - the range | 范围
      Returns:
      the sub range map | 子范围映射
    • put

      void put(Range<K> range, V value)
      Associate a range with a value. 将范围与值关联。
      Parameters:
      range - the range | 范围
      value - the value | 值
    • putCoalescing

      void putCoalescing(Range<K> range, V value)
      Associate a range with a value, coalescing with adjacent ranges with the same value. 将范围与值关联,与具有相同值的相邻范围合并。
      Parameters:
      range - the range | 范围
      value - the value | 值
    • putAll

      void putAll(RangeMap<K, ? extends V> rangeMap)
      Put all mappings from another range map. 从另一个范围映射放入所有映射。
      Parameters:
      rangeMap - the other range map | 另一个范围映射
    • remove

      void remove(Range<K> range)
      Remove a range from this map. 从此映射移除范围。
      Parameters:
      range - the range to remove | 要移除的范围
    • clear

      void clear()
      Clear all mappings. 清除所有映射。