kotlin-range-sets / com.github.jonpeterson.kotlin.ranges / RangeSet

RangeSet

abstract class RangeSet<T : Comparable<T>> : MutableSet<ClosedRange<T>>, Cloneable (source)

Base class for implementing a MutableSet of ClosedRanges.

Ranges in the set will always be in a normalized state. This means that ranges are kept in order and overlapping or adjacent ranges will be joined.

Some operations are not designed to be thread-safe. Wrap this in Collections.synchronizedSet if thread-safety is needed.



Parameters

T - the type of ranges in this set


Constructors

<init> RangeSet()

Creates a set with no ranges.

RangeSet(ranges: List<ClosedRange<T>>)RangeSet(rangeSet: RangeSet<T>)

Creates a set with ranges shallow-copied from another RangeSet.

Properties

size open val size: Int

Functions

add open fun add(element: ClosedRange<T>): Boolean

Adds range of values to the set; addition set logic.

addAll open fun addAll(elements: Collection<ClosedRange<T>>): Boolean

Adds ranges of values to the set; addition set logic.

clear open fun clear(): Unit

Removes all values from the set.

clone abstract fun clone(): RangeSet<T>
contains open fun contains(element: ClosedRange<T>): Boolean

Checks if all values in the specified range are present in the set.

containsAll open fun containsAll(elements: Collection<ClosedRange<T>>): Boolean

Checks if all values in the specified ranges are present in the set.

containsValue fun containsValue(value: T): Boolean

Checks if the specified value is present in the set.

createRange abstract fun createRange(start: T, endInclusive: T): ClosedRange<T>
decrementValue abstract fun decrementValue(value: T): T
difference fun difference(element: ClosedRange<T>): RangeSet<T>

Creates a new RangeSet containing values not present in this set within the specified range.

differenceAll fun differenceAll(elements: Collection<ClosedRange<T>>): RangeSet<T>

Creates a new RangeSet containing values not present in this set within the specified ranges.

equals open fun equals(other: Any?): Boolean
gaps fun gaps(): RangeSet<T>

Creates a new RangeSet containing missing values between the ranges of this set.

hashCode open fun hashCode(): Int
incrementValue abstract fun incrementValue(value: T): T
isEmpty open fun isEmpty(): Boolean
iterator open fun iterator(): MutableIterator<ClosedRange<T>>
remove open fun remove(element: ClosedRange<T>): Boolean

Removes a range of values from the set; subtraction set logic.

removeAll open fun removeAll(elements: Collection<ClosedRange<T>>): Boolean

Removes ranges of values from the set; subtraction set logic.

retain fun retain(element: ClosedRange<T>): Boolean

Removes all values from set except those contained in the specified range; intersection set logic.

retainAll open fun retainAll(elements: Collection<ClosedRange<T>>): Boolean

Removes all values from set except those contained in the specified ranges; intersection set logic.

Inheritors

CharRangeSet class CharRangeSet : RangeSet<Char>
IntRangeSet class IntRangeSet : RangeSet<Int>
LongRangeSet class LongRangeSet : RangeSet<Long>