class Range<T : Comparable<*>> : Any

Represents a mathematical range. See wikipedia article of interval.

Constructors

<init>

constructor(_range: GRange<T>)

Represents a mathematical range. See wikipedia article of interval.

Parameters

Name Description
_range: GRange<T>

adapted guava range class

Methods

contains

operator fun contains(value: T): Boolean

Returns true, if the value is within this Range bounds.

Parameters

Name Description
value: T

ReturnValue

Name Description
Boolean

containsResult

fun containsResult(value: T): Result<Boolean, IllegalArgumentException>

Returns Result.Success, if the value is contained within this Range.

Parameters

Name Description
value: T

value to be checked

ReturnValue

Name Description
Result<Boolean, IllegalArgumentException>

Result.Success, if value is fuzzily contained; Result.Failure, otherwise

hasLowerBound

fun hasLowerBound(): ()

Returns true, if this range has a lower endpoint.

ReturnValue

Name Description
()

hasUpperBound

fun hasUpperBound(): ()

Returns true, if this range has an upper endpoint.

ReturnValue

Name Description
()

lowerEndpointOrNull

fun lowerEndpointOrNull(): T?

Returns the lower endpoint, if this range has one; otherwise null is returned.

ReturnValue

Name Description
T?

upperEndpointOrNull

fun upperEndpointOrNull(): T?

Returns the upper endpoint, if this range has one; otherwise null is returned.

ReturnValue

Name Description
T?

lowerEndpointResult

fun lowerEndpointResult(): Result<T, IllegalStateException>

Returns the lower endpoint as result.

ReturnValue

Name Description
Result<T, IllegalStateException>

upperEndpointResult

fun upperEndpointResult(): Result<T, IllegalStateException>

Returns the upper endpoint as result.

ReturnValue

Name Description
Result<T, IllegalStateException>

lowerBoundType

fun lowerBoundType(): BoundType

Returns the lower BoundType of this range.

ReturnValue

Name Description
BoundType

upperBoundType

fun upperBoundType(): BoundType

Returns the upper BoundType of this range.

ReturnValue

Name Description
BoundType

isEmpty

fun isEmpty(): ()

Returns true, if this range has the form v..vorv..v.

ReturnValue

Name Description
()

isNotEmpty

fun isNotEmpty(): !isEmpty()

ReturnValue

Name Description
!isEmpty()

isConnected

fun isConnected(other: Range<T>): (other: Range)

Returns true, if there exists a (possibly empty) range which is enclosed by both this range and other.

For example, [1, 3) and 4,5 are not connected [1, 3) and 2,5 are connected [1, 3) and 3,5 are connected

Parameters

Name Description
other: Range<T>

other range

ReturnValue

Name Description
(other: Range)

true, if this and other range is connected

encloses

infix fun encloses(other: Range<T>): infix

Returns true, if the bounds of the other range do not extend the bounds of this range.

Parameters

Name Description
other: Range<T>

range to be evaluated

ReturnValue

Name Description
infix

true if, this range encloses the other range

intersection

fun intersection(connectedRange: Range<T>): Range<T>

Returns the intersecting range of this range with the other connectedRange.

Parameters

Name Description
connectedRange: Range<T>

range that must be connected to this range

ReturnValue

Name Description
Range<T>

intersecting range

span

fun span(other: Range<T>): (other: Range)

Returns the minimal range that encloses this and the other range. For example, the span of [1, 3) and 5,7 is 1,7.

Parameters

Name Description
other: Range<T>

other range

ReturnValue

Name Description
(other: Range)

range that encloses this and the other range

join

fun join(connectedRange: Range<T>): Range<T>

Joins this and a connectedRange by building the span.

Parameters

Name Description
connectedRange: Range<T>

other range that must be connected to this range

ReturnValue

Name Description
Range<T>

joined Range

equals

fun equals(other: Any?): Boolean

Parameters

Name Description
other: Any?

ReturnValue

Name Description
Boolean

hashCode

fun hashCode(): Int

ReturnValue

Name Description
Int

toRangeG

fun toRangeG(): ()<T>

Conversion to Guava range.

ReturnValue

Name Description
()<T>

toString

fun toString(): String

Conversion to String.

ReturnValue

Name Description
String

Extensions

arrange

fun Range<Double>.arrange(step: Double, includeClosedEndPoint: Boolean, tolerance: Double): DoubleArray

Arranges an array of Double with step size.

Receiver

Name Description
Range<Double>

Parameters

Name Description
step: Double

size between two values

includeClosedEndPoint: Boolean

true, if endpoint of the Range is to be included

tolerance: Double

tolerance for checking whether endpoint is already included

ReturnValue

Name Description
DoubleArray

DoubleArray of arranged values from lowerEndPoint to upperEndPoint of Range

fuzzyContains

fun Range<Double>.fuzzyContains(value: Double, tolerance: Double): Boolean

Returns true, if the value is fuzzily contained within this Range by the tolerance.

Receiver

Name Description
Range<Double>

Parameters

Name Description
value: Double

value to be checked

tolerance: Double

allowed tolerance fuzziness

ReturnValue

Name Description
Boolean

true, if value is contained

fuzzyContainsResult

fun Range<Double>.fuzzyContainsResult(value: Double, tolerance: Double): Result<Boolean, IllegalArgumentException>

Returns Result.Success, if the value is fuzzily contained within this Range by the tolerance.

Receiver

Name Description
Range<Double>

Parameters

Name Description
value: Double

value to be checked

tolerance: Double

allowed tolerance fuzziness

ReturnValue

Name Description
Result<Boolean, IllegalArgumentException>

Result.Success, if value is fuzzily contained; Result.Failure, otherwise

widened

fun Range<Double>.widened(lowerWideningValue: Double, upperWideningValue: Double): Range<Double>

Widens the lower bound of the Range by lowerWideningValue and the upper bound of the Range by upperWideningValue.

Receiver

Name Description
Range<Double>

Parameters

Name Description
lowerWideningValue: Double

the value for widening the lower bound

upperWideningValue: Double

the value for widening the upper bound

ReturnValue

Name Description
Range<Double>

widened Range

widened

fun Range<Double>.widened(wideningValue: Double): Range<Double>

Widens the Range by wideningValue on the lower and upper bound.

Receiver

Name Description
Range<Double>

Parameters

Name Description
wideningValue: Double

value for widening the lower and upper bound

ReturnValue

Name Description
Range<Double>

widened Range

fuzzyEncloses

fun Range<Double>.fuzzyEncloses(other: Range<Double>, tolerance: Double): Boolean

Returns true, if the other is fuzzily enclosed with a tolerance.

Receiver

Name Description
Range<Double>

Parameters

Name Description
other: Range<Double>

other range to be checked

tolerance: Double

allowed tolerance

ReturnValue

Name Description
Boolean

true, if other is enclosed

shift

fun Range<Double>.shift(value: Double): Range<Double>

Shifts the Range by a value.

Receiver

Name Description
Range<Double>

Parameters

Name Description
value: Double

value the Range is to be shifted by

ReturnValue

Name Description
Range<Double>

shifted Range

shiftLowerEndpointTo

fun Range<Double>.shiftLowerEndpointTo(value: Double): Range<Double>

Shift the Range so that the lower endpoint is represented by the value.

Receiver

Name Description
Range<Double>

Parameters

Name Description
value: Double

new lower endpoint after shifting Range

ReturnValue

Name Description
Range<Double>

shifted Range

toRangeSet

fun <T : Comparable<*>> Range<T>.toRangeSet(): RangeSet<T>

Conversion to RangeSet.

Receiver

Name Description
Range<T>

Range to be converted

ReturnValue

Name Description
RangeSet<T>

CompanionObject

Range

class Range<T : Comparable<*>> : Any

Represents a mathematical range. See wikipedia article of interval.

Methods

rangeOfNullable

fun <T : Comparable<*>> rangeOfNullable(lowerBoundType: BoundType, lowerEndpoint: T?, upperBoundType: BoundType, upperEndpoint: T?): Range<T>

Creates a Range based on bound type and endpoint values. If bound type is BoundType.NONE the respective endpoint value must be null for consistency reasons.

Parameters

Name Description
lowerBoundType: BoundType

lower bound type which must be consistent with lowerEndpoint

lowerEndpoint: T?

value for lower endpoint

upperBoundType: BoundType

upper bound type which must be consistent with upperEndpoint

upperEndpoint: T?

value for upper endpoint

ReturnValue

Name Description
Range<T>

created Range

range

fun <T : Comparable<*>> range(lowerBoundType: BoundType, lowerEndpoint: T, upperBoundType: BoundType, upperEndpoint: T): Range<T>

Creates a Range.

Parameters

Name Description
lowerBoundType: BoundType

type of lower bound; if BoundType.NONE the lowerEndpoint value is ignored

lowerEndpoint: T

value for lower endpoint

upperBoundType: BoundType

type of lower bound; if BoundType.NONE the upperEndpoint value is ignored

upperEndpoint: T

value for upper endpoint

ReturnValue

Name Description
Range<T>

created Range

open

fun <T : Comparable<*>> open(lower: T, upper: T): Range<T>

Creates a Range of the form (lower, upper).

Parameters

Name Description
lower: T
upper: T

ReturnValue

Name Description
Range<T>

closed

fun <T : Comparable<*>> closed(lower: T, upper: T): Range<T>

Creates a Range of the form [lower, upper].

Parameters

Name Description
lower: T
upper: T

ReturnValue

Name Description
Range<T>

openClosed

fun <T : Comparable<*>> openClosed(lower: T, upper: T): Range<T>

Creates a Range of the form (lower, upper].

Parameters

Name Description
lower: T
upper: T

ReturnValue

Name Description
Range<T>

closedOpen

fun <T : Comparable<*>> closedOpen(lower: T, upper: T): Range<T>

Creates a Range of the form [lower, upper).

Parameters

Name Description
lower: T
upper: T

ReturnValue

Name Description
Range<T>

greaterThan

fun <T : Comparable<*>> greaterThan(endpoint: T): Range<T>

Creates a Range of the form (endpoint, ∞).

Parameters

Name Description
endpoint: T

ReturnValue

Name Description
Range<T>

atLeast

fun <T : Comparable<*>> atLeast(endpoint: T): Range<T>

Creates a Range of the form [endpoint, ∞).

Parameters

Name Description
endpoint: T

ReturnValue

Name Description
Range<T>

lessThan

fun <T : Comparable<*>> lessThan(endpoint: T): Range<T>

Creates a Range of the form (-∞, endpoint).

Parameters

Name Description
endpoint: T

ReturnValue

Name Description
Range<T>

atMost

fun <T : Comparable<*>> atMost(endpoint: T): Range<T>

Creates a Range of the form (-∞, endpoint].

Parameters

Name Description
endpoint: T

ReturnValue

Name Description
Range<T>

all

fun <T : Comparable<*>> all(): Range<T>

Creates a Range that contains every value in T.

ReturnValue

Name Description
Range<T>

downTo

fun <T : Comparable<*>> downTo(endpoint: T, boundType: BoundType): Range<T>

Creates a Range of the form [endpoint, ∞) or (endpoint, ∞) depending on the boundType.

Parameters

Name Description
endpoint: T

lower endpoint

boundType: BoundType

type of bound which must not be BoundType.NONE

ReturnValue

Name Description
Range<T>

created Range

upTo

fun <T : Comparable<*>> upTo(endpoint: T, boundType: BoundType): Range<T>

Creates a Range of the form (-∞, endpoint) or (-∞, endpoint] depending on the boundType.

Parameters

Name Description
endpoint: T

upper endpoint

boundType: BoundType

type of bound which must not be BoundType.NONE

ReturnValue

Name Description
Range<T>

created Range

closedX

fun <T : Comparable<*>> closedX(lower: T, upper: T, upperBoundType: BoundType): Range<T>

Creates a Range of the form [lower, upper] or [lower, upper) depending on the upperBoundType.

Parameters

Name Description
lower: T

lower endpoint

upper: T

upper endpoint

upperBoundType: BoundType

type of upper bound which must not be BoundType.NONE

ReturnValue

Name Description
Range<T>

created Range