Interface RangeSet<C extends Comparable<? super C>>

Type Parameters:
C - the type of range endpoints | 范围端点类型
All Known Implementing Classes:
ImmutableRangeSet, TreeRangeSet

public interface RangeSet<C extends Comparable<? super C>>
RangeSet - Range Set Interface RangeSet - 范围集合接口

A set of ranges that automatically coalesces overlapping and adjacent ranges.

自动合并重叠和相邻范围的范围集合。

Features | 主要功能:

  • Automatic range coalescing - 自动范围合并
  • Efficient range queries - 高效范围查询
  • Complement and intersection operations - 补集和交集操作

Usage Examples | 使用示例:

RangeSet<Integer> rangeSet = TreeRangeSet.create();
rangeSet.add(Range.closed(1, 10));   // {[1, 10]}
rangeSet.add(Range.closed(5, 15));   // {[1, 15]} (coalesced)
rangeSet.add(Range.closed(20, 30));  // {[1, 15], [20, 30]}

boolean contains = rangeSet.contains(5);  // true
Range<Integer> enclosing = rangeSet.rangeContaining(5);  // [1, 15]

Security | 安全性:

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

    • contains

      boolean contains(C value)
      Check if the value is contained in any range. 检查值是否包含在任何范围中。
      Parameters:
      value - the value | 值
      Returns:
      true if contained | 如果包含则返回 true
    • rangeContaining

      Range<C> rangeContaining(C value)
      Return the range containing the value, or null. 返回包含该值的范围,如果不存在则返回 null。
      Parameters:
      value - the value | 值
      Returns:
      the containing range, or null | 包含的范围,或 null
    • encloses

      boolean encloses(Range<C> otherRange)
      Check if this range set encloses the given range. 检查此范围集合是否完全包含给定范围。
      Parameters:
      otherRange - the range to check | 要检查的范围
      Returns:
      true if enclosed | 如果完全包含则返回 true
    • enclosesAll

      boolean enclosesAll(RangeSet<C> other)
      Check if this range set encloses all ranges in the other set. 检查此范围集合是否完全包含另一个集合中的所有范围。
      Parameters:
      other - the other range set | 另一个范围集合
      Returns:
      true if all enclosed | 如果全部包含则返回 true
    • intersects

      boolean intersects(Range<C> otherRange)
      Check if this range set intersects the given range. 检查此范围集合是否与给定范围相交。
      Parameters:
      otherRange - the range to check | 要检查的范围
      Returns:
      true if intersects | 如果相交则返回 true
    • isEmpty

      boolean isEmpty()
      Check if this range set is empty. 检查此范围集合是否为空。
      Returns:
      true if empty | 如果为空则返回 true
    • asRanges

      Set<Range<C>> asRanges()
      Return all ranges as a set. 以集合形式返回所有范围。
      Returns:
      the set of ranges | 范围集合
    • asDescendingSetOfRanges

      Set<Range<C>> asDescendingSetOfRanges()
      Return all ranges as a descending set. 以降序集合形式返回所有范围。
      Returns:
      the descending set of ranges | 降序范围集合
    • complement

      RangeSet<C> complement()
      Return the complement of this range set. 返回此范围集合的补集。
      Returns:
      the complement | 补集
    • subRangeSet

      RangeSet<C> subRangeSet(Range<C> view)
      Return a sub range set within the given range. 返回给定范围内的子范围集合。
      Parameters:
      view - the viewing range | 视图范围
      Returns:
      the sub range set | 子范围集合
    • span

      Range<C> span()
      Return the minimal range that encloses all ranges. 返回包含所有范围的最小范围。
      Returns:
      the span | 跨度
    • add

      void add(Range<C> range)
      Add a range to this set. 向此集合添加范围。
      Parameters:
      range - the range to add | 要添加的范围
    • remove

      void remove(Range<C> range)
      Remove a range from this set. 从此集合移除范围。
      Parameters:
      range - the range to remove | 要移除的范围
    • addAll

      void addAll(RangeSet<C> other)
      Add all ranges from another range set. 从另一个范围集合添加所有范围。
      Parameters:
      other - the other range set | 另一个范围集合
    • removeAll

      void removeAll(RangeSet<C> other)
      Remove all ranges in another range set. 移除另一个范围集合中的所有范围。
      Parameters:
      other - the other range set | 另一个范围集合
    • clear

      void clear()
      Clear all ranges. 清除所有范围。