Rename ClosedComparableRange to ClosedFloatingPointRange

This commit is contained in:
Ilya Gorbunov
2016-12-16 03:14:17 +03:00
parent 919c77b950
commit 10f8e70322
10 changed files with 31 additions and 31 deletions
@@ -620,7 +620,7 @@ public header fun Double.coerceIn(minimumValue: Double, maximumValue: Double): D
*
* @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`.
*/
public header fun <T: Comparable<T>> T.coerceIn(range: ClosedComparableRange<T>): T
public header fun <T: Comparable<T>> T.coerceIn(range: ClosedFloatingPointRange<T>): T
/**
* Ensures that this value lies in the specified [range].
+4 -4
View File
@@ -869,7 +869,7 @@ public fun Double.coerceIn(minimumValue: Double, maximumValue: Double): Double {
*
* @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`.
*/
public fun <T: Comparable<T>> T.coerceIn(range: ClosedComparableRange<T>): T {
public fun <T: Comparable<T>> T.coerceIn(range: ClosedFloatingPointRange<T>): T {
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
return when {
// this < start equiv to this <= start && !(this >= start)
@@ -886,7 +886,7 @@ public fun <T: Comparable<T>> T.coerceIn(range: ClosedComparableRange<T>): T {
* @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`.
*/
public fun <T: Comparable<T>> T.coerceIn(range: ClosedRange<T>): T {
if (range is ClosedComparableRange) {
if (range is ClosedFloatingPointRange) {
return this.coerceIn<T>(range)
}
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
@@ -903,7 +903,7 @@ public fun <T: Comparable<T>> T.coerceIn(range: ClosedRange<T>): T {
* @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`.
*/
public fun Int.coerceIn(range: ClosedRange<Int>): Int {
if (range is ClosedComparableRange) {
if (range is ClosedFloatingPointRange) {
return this.coerceIn<Int>(range)
}
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
@@ -920,7 +920,7 @@ public fun Int.coerceIn(range: ClosedRange<Int>): Int {
* @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`.
*/
public fun Long.coerceIn(range: ClosedRange<Long>): Long {
if (range is ClosedComparableRange) {
if (range is ClosedFloatingPointRange) {
return this.coerceIn<Long>(range)
}
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
+6 -6
View File
@@ -3,14 +3,14 @@
package kotlin.ranges
/**
* Represents a range of values (for example, numbers or characters).
* Represents a range of floating point numbers.
* Extends [ClosedRange] interface providing custom operation [lessThanOrEquals] for comparing values of range domain type.
*
* This interface is implemented by floating point ranges returned by [Float.rangeTo] and [Double.rangeTo] operators to
* achieve IEEE-754 comparison order instead of total order of floating point numbers.
*/
@SinceKotlin("1.1")
public interface ClosedComparableRange<T: Comparable<T>> : ClosedRange<T> {
public interface ClosedFloatingPointRange<T: Comparable<T>> : ClosedRange<T> {
override fun contains(value: T): Boolean = lessThanOrEquals(start, value) && lessThanOrEquals(value, endInclusive)
override fun isEmpty(): Boolean = !lessThanOrEquals(start, endInclusive)
@@ -48,7 +48,7 @@ private open class ComparableRange<T: Comparable<T>> (
private class ClosedDoubleRange (
start: Double,
endInclusive: Double
) : ClosedComparableRange<Double> {
) : ClosedFloatingPointRange<Double> {
private val _start = start
private val _endInclusive = endInclusive
override val start: Double get() = _start
@@ -79,7 +79,7 @@ private class ClosedDoubleRange (
private class ClosedFloatRange (
start: Float,
endInclusive: Float
): ClosedComparableRange<Float> {
): ClosedFloatingPointRange<Float> {
private val _start = start
private val _endInclusive = endInclusive
override val start: Float get() = _start
@@ -114,7 +114,7 @@ public operator fun <T: Comparable<T>> T.rangeTo(that: T): ClosedRange<T> = Comp
* Numbers are compared with the ends of this range according to IEEE-754.
*/
@SinceKotlin("1.1")
public operator fun Double.rangeTo(that: Double): ClosedComparableRange<Double> = ClosedDoubleRange(this, that)
public operator fun Double.rangeTo(that: Double): ClosedFloatingPointRange<Double> = ClosedDoubleRange(this, that)
/**
* Creates a range from this [Float] value to the specified [other] value.
@@ -123,7 +123,7 @@ public operator fun Double.rangeTo(that: Double): ClosedComparableRange<Double>
*/
@JvmVersion
@SinceKotlin("1.1")
public operator fun Float.rangeTo(that: Float): ClosedComparableRange<Float> = ClosedFloatRange(this, that)
public operator fun Float.rangeTo(that: Float): ClosedFloatingPointRange<Float> = ClosedFloatRange(this, that)
internal fun checkStepIsPositive(isPositive: Boolean, step: Number) {
@@ -1888,15 +1888,15 @@ public abstract interface class kotlin/properties/ReadWriteProperty {
public abstract fun setValue (Ljava/lang/Object;Lkotlin/reflect/KProperty;Ljava/lang/Object;)V
}
public abstract interface class kotlin/ranges/ClosedComparableRange : kotlin/ranges/ClosedRange {
public abstract interface class kotlin/ranges/ClosedFloatingPointRange : kotlin/ranges/ClosedRange {
public abstract fun contains (Ljava/lang/Comparable;)Z
public abstract fun isEmpty ()Z
public abstract fun lessThanOrEquals (Ljava/lang/Comparable;Ljava/lang/Comparable;)Z
}
public final class kotlin/ranges/ClosedComparableRange$DefaultImpls {
public static fun contains (Lkotlin/ranges/ClosedComparableRange;Ljava/lang/Comparable;)Z
public static fun isEmpty (Lkotlin/ranges/ClosedComparableRange;)Z
public final class kotlin/ranges/ClosedFloatingPointRange$DefaultImpls {
public static fun contains (Lkotlin/ranges/ClosedFloatingPointRange;Ljava/lang/Comparable;)Z
public static fun isEmpty (Lkotlin/ranges/ClosedFloatingPointRange;)Z
}
public final class kotlin/ranges/RangesKt {
@@ -1927,7 +1927,7 @@ public final class kotlin/ranges/RangesKt {
public static final fun coerceIn (JJJ)J
public static final fun coerceIn (JLkotlin/ranges/ClosedRange;)J
public static final fun coerceIn (Ljava/lang/Comparable;Ljava/lang/Comparable;Ljava/lang/Comparable;)Ljava/lang/Comparable;
public static final fun coerceIn (Ljava/lang/Comparable;Lkotlin/ranges/ClosedComparableRange;)Ljava/lang/Comparable;
public static final fun coerceIn (Ljava/lang/Comparable;Lkotlin/ranges/ClosedFloatingPointRange;)Ljava/lang/Comparable;
public static final fun coerceIn (Ljava/lang/Comparable;Lkotlin/ranges/ClosedRange;)Ljava/lang/Comparable;
public static final fun coerceIn (SSS)S
public static final fun doubleRangeContains (Lkotlin/ranges/ClosedRange;B)Z
@@ -1967,8 +1967,8 @@ public final class kotlin/ranges/RangesKt {
public static final fun longRangeContains (Lkotlin/ranges/ClosedRange;F)Z
public static final fun longRangeContains (Lkotlin/ranges/ClosedRange;I)Z
public static final fun longRangeContains (Lkotlin/ranges/ClosedRange;S)Z
public static final fun rangeTo (DD)Lkotlin/ranges/ClosedComparableRange;
public static final fun rangeTo (FF)Lkotlin/ranges/ClosedComparableRange;
public static final fun rangeTo (DD)Lkotlin/ranges/ClosedFloatingPointRange;
public static final fun rangeTo (FF)Lkotlin/ranges/ClosedFloatingPointRange;
public static final fun rangeTo (Ljava/lang/Comparable;Ljava/lang/Comparable;)Lkotlin/ranges/ClosedRange;
public static final fun reversed (Lkotlin/ranges/CharProgression;)Lkotlin/ranges/CharProgression;
public static final fun reversed (Lkotlin/ranges/IntProgression;)Lkotlin/ranges/IntProgression;
@@ -61,7 +61,7 @@ fun comparables(): List<GenericFunction> {
}
body(Generic) {
"""
if (range is ClosedComparableRange) {
if (range is ClosedFloatingPointRange) {
return this.coerceIn<T>(range)
}
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: ${'$'}range.")
@@ -74,7 +74,7 @@ fun comparables(): List<GenericFunction> {
}
body(Primitives) {
"""
if (range is ClosedComparableRange) {
if (range is ClosedFloatingPointRange) {
return this.coerceIn<T>(range)
}
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: ${'$'}range.")
@@ -87,7 +87,7 @@ fun comparables(): List<GenericFunction> {
}
}
templates add f("coerceIn(range: ClosedComparableRange<T>)") {
templates add f("coerceIn(range: ClosedFloatingPointRange<T>)") {
sourceFile(SourceFile.Ranges)
only(Generic)
returns("SELF")