Deprecate Double, Float and Comparable range implementations.

This commit is contained in:
Ilya Gorbunov
2015-10-13 20:38:15 +03:00
parent aeb4abe39d
commit 69dc6701cc
15 changed files with 279 additions and 94 deletions
@@ -139,6 +139,7 @@ class LongProgressionIterator(start: Long, end: Long, val increment: Long) : Lon
* An iterator over a progression of values of type `Float`. * An iterator over a progression of values of type `Float`.
* @property increment the number by which the value is incremented on each step. * @property increment the number by which the value is incremented on each step.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
class FloatProgressionIterator(start: Float, val end: Float, val increment: Float) : FloatIterator() { class FloatProgressionIterator(start: Float, val end: Float, val increment: Float) : FloatIterator() {
private var next = start private var next = start
@@ -155,6 +156,7 @@ class FloatProgressionIterator(start: Float, val end: Float, val increment: Floa
* An iterator over a progression of values of type `Double`. * An iterator over a progression of values of type `Double`.
* @property increment the number by which the value is incremented on each step. * @property increment the number by which the value is incremented on each step.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
class DoubleProgressionIterator(start: Double, val end: Double, val increment: Double) : DoubleIterator() { class DoubleProgressionIterator(start: Double, val end: Double, val increment: Double) : DoubleIterator() {
private var next = start private var next = start
+4
View File
@@ -153,6 +153,8 @@ public class LongProgression(
override fun toString(): String = if (increment > 0) "$start..$end step $increment" else "$start downTo $end step ${-increment}" override fun toString(): String = if (increment > 0) "$start..$end step $increment" else "$start downTo $end step ${-increment}"
} }
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
/** /**
* A progression of values of type `Float`. * A progression of values of type `Float`.
*/ */
@@ -181,6 +183,8 @@ public class FloatProgression(
override fun toString(): String = if (increment > 0) "$start..$end step $increment" else "$start downTo $end step ${-increment}" override fun toString(): String = if (increment > 0) "$start..$end step $increment" else "$start downTo $end step ${-increment}"
} }
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
/** /**
* A progression of values of type `Double`. * A progression of values of type `Double`.
*/ */
+4
View File
@@ -158,6 +158,8 @@ public class LongRange(override val start: Long, override val end: Long) : Range
} }
} }
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
/** /**
* A range of values of type `Float`. * A range of values of type `Float`.
*/ */
@@ -186,6 +188,8 @@ public class FloatRange(override val start: Float, override val end: Float) : Ra
} }
} }
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
/** /**
* A range of values of type `Double`. * A range of values of type `Double`.
*/ */
@@ -57,11 +57,11 @@ class ${t}ProgressionIterator(start: $t, end: $t, val increment: $incrementType)
fun floatingPointProgressionIterator(kind: ProgressionKind): String { fun floatingPointProgressionIterator(kind: ProgressionKind): String {
val t = kind.capitalized val t = kind.capitalized
return """/** return """/**
* An iterator over a progression of values of type `$t`. * An iterator over a progression of values of type `$t`.
* @property increment the number by which the value is incremented on each step. * @property increment the number by which the value is incremented on each step.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
class ${t}ProgressionIterator(start: $t, val end: $t, val increment: $t) : ${t}Iterator() { class ${t}ProgressionIterator(start: $t, val end: $t, val increment: $t) : ${t}Iterator() {
private var next = start private var next = start
@@ -64,6 +64,11 @@ class GenerateProgressions(out: PrintWriter) : BuiltInsSourceGenerator(out) {
" }" " }"
} }
if (kind == FLOAT || kind == DOUBLE) {
out.println("""@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)""")
out.println("""@Suppress("DEPRECATION_ERROR")""")
}
out.println( out.println(
"""/** """/**
* A progression of values of type `$t`. * A progression of values of type `$t`.
@@ -64,6 +64,11 @@ class GenerateRanges(out: PrintWriter) : BuiltInsSourceGenerator(out) {
val toString = "\"\$start..\$end\"" val toString = "\"\$start..\$end\""
if (kind == FLOAT || kind == DOUBLE) {
out.println("""@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)""")
out.println("""@Suppress("DEPRECATION_ERROR")""")
}
out.println( out.println(
"""/** """/**
* A range of values of type `$t`. * A range of values of type `$t`.
+168 -89
View File
@@ -39,7 +39,9 @@ public operator fun Range<Short>.contains(item: Byte): Boolean {
/** /**
* Checks if the specified [item] belongs to this range. * Checks if the specified [item] belongs to this range.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("doubleRangeContains") @kotlin.jvm.JvmName("doubleRangeContains")
@Suppress("DEPRECATION_ERROR")
public operator fun Range<Double>.contains(item: Byte): Boolean { public operator fun Range<Double>.contains(item: Byte): Boolean {
return start <= item && item <= end return start <= item && item <= end
} }
@@ -47,7 +49,9 @@ public operator fun Range<Double>.contains(item: Byte): Boolean {
/** /**
* Checks if the specified [item] belongs to this range. * Checks if the specified [item] belongs to this range.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("floatRangeContains") @kotlin.jvm.JvmName("floatRangeContains")
@Suppress("DEPRECATION_ERROR")
public operator fun Range<Float>.contains(item: Byte): Boolean { public operator fun Range<Float>.contains(item: Byte): Boolean {
return start <= item && item <= end return start <= item && item <= end
} }
@@ -87,7 +91,9 @@ public operator fun Range<Short>.contains(item: Double): Boolean {
/** /**
* Checks if the specified [item] belongs to this range. * Checks if the specified [item] belongs to this range.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("floatRangeContains") @kotlin.jvm.JvmName("floatRangeContains")
@Suppress("DEPRECATION_ERROR")
public operator fun Range<Float>.contains(item: Double): Boolean { public operator fun Range<Float>.contains(item: Double): Boolean {
return start <= item && item <= end return start <= item && item <= end
} }
@@ -127,7 +133,9 @@ public operator fun Range<Short>.contains(item: Float): Boolean {
/** /**
* Checks if the specified [item] belongs to this range. * Checks if the specified [item] belongs to this range.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("doubleRangeContains") @kotlin.jvm.JvmName("doubleRangeContains")
@Suppress("DEPRECATION_ERROR")
public operator fun Range<Double>.contains(item: Float): Boolean { public operator fun Range<Double>.contains(item: Float): Boolean {
return start <= item && item <= end return start <= item && item <= end
} }
@@ -159,7 +167,9 @@ public operator fun Range<Short>.contains(item: Int): Boolean {
/** /**
* Checks if the specified [item] belongs to this range. * Checks if the specified [item] belongs to this range.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("doubleRangeContains") @kotlin.jvm.JvmName("doubleRangeContains")
@Suppress("DEPRECATION_ERROR")
public operator fun Range<Double>.contains(item: Int): Boolean { public operator fun Range<Double>.contains(item: Int): Boolean {
return start <= item && item <= end return start <= item && item <= end
} }
@@ -167,7 +177,9 @@ public operator fun Range<Double>.contains(item: Int): Boolean {
/** /**
* Checks if the specified [item] belongs to this range. * Checks if the specified [item] belongs to this range.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("floatRangeContains") @kotlin.jvm.JvmName("floatRangeContains")
@Suppress("DEPRECATION_ERROR")
public operator fun Range<Float>.contains(item: Int): Boolean { public operator fun Range<Float>.contains(item: Int): Boolean {
return start <= item && item <= end return start <= item && item <= end
} }
@@ -199,7 +211,9 @@ public operator fun Range<Short>.contains(item: Long): Boolean {
/** /**
* Checks if the specified [item] belongs to this range. * Checks if the specified [item] belongs to this range.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("doubleRangeContains") @kotlin.jvm.JvmName("doubleRangeContains")
@Suppress("DEPRECATION_ERROR")
public operator fun Range<Double>.contains(item: Long): Boolean { public operator fun Range<Double>.contains(item: Long): Boolean {
return start <= item && item <= end return start <= item && item <= end
} }
@@ -207,7 +221,9 @@ public operator fun Range<Double>.contains(item: Long): Boolean {
/** /**
* Checks if the specified [item] belongs to this range. * Checks if the specified [item] belongs to this range.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("floatRangeContains") @kotlin.jvm.JvmName("floatRangeContains")
@Suppress("DEPRECATION_ERROR")
public operator fun Range<Float>.contains(item: Long): Boolean { public operator fun Range<Float>.contains(item: Long): Boolean {
return start <= item && item <= end return start <= item && item <= end
} }
@@ -239,7 +255,9 @@ public operator fun Range<Byte>.contains(item: Short): Boolean {
/** /**
* Checks if the specified [item] belongs to this range. * Checks if the specified [item] belongs to this range.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("doubleRangeContains") @kotlin.jvm.JvmName("doubleRangeContains")
@Suppress("DEPRECATION_ERROR")
public operator fun Range<Double>.contains(item: Short): Boolean { public operator fun Range<Double>.contains(item: Short): Boolean {
return start <= item && item <= end return start <= item && item <= end
} }
@@ -247,7 +265,9 @@ public operator fun Range<Double>.contains(item: Short): Boolean {
/** /**
* Checks if the specified [item] belongs to this range. * Checks if the specified [item] belongs to this range.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("floatRangeContains") @kotlin.jvm.JvmName("floatRangeContains")
@Suppress("DEPRECATION_ERROR")
public operator fun Range<Float>.contains(item: Short): Boolean { public operator fun Range<Float>.contains(item: Short): Boolean {
return start <= item && item <= end return start <= item && item <= end
} }
@@ -288,6 +308,8 @@ public infix fun Short.downTo(to: Byte): ShortProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Double.downTo(to: Byte): DoubleProgression { public infix fun Double.downTo(to: Byte): DoubleProgression {
return DoubleProgression(this, to.toDouble(), -1.0) return DoubleProgression(this, to.toDouble(), -1.0)
} }
@@ -296,6 +318,8 @@ public infix fun Double.downTo(to: Byte): DoubleProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Float.downTo(to: Byte): FloatProgression { public infix fun Float.downTo(to: Byte): FloatProgression {
return FloatProgression(this, to.toFloat(), -1.0F) return FloatProgression(this, to.toFloat(), -1.0F)
} }
@@ -312,6 +336,8 @@ public infix fun Char.downTo(to: Char): CharProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Int.downTo(to: Double): DoubleProgression { public infix fun Int.downTo(to: Double): DoubleProgression {
return DoubleProgression(this.toDouble(), to, -1.0) return DoubleProgression(this.toDouble(), to, -1.0)
} }
@@ -320,6 +346,8 @@ public infix fun Int.downTo(to: Double): DoubleProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Long.downTo(to: Double): DoubleProgression { public infix fun Long.downTo(to: Double): DoubleProgression {
return DoubleProgression(this.toDouble(), to, -1.0) return DoubleProgression(this.toDouble(), to, -1.0)
} }
@@ -328,6 +356,8 @@ public infix fun Long.downTo(to: Double): DoubleProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Byte.downTo(to: Double): DoubleProgression { public infix fun Byte.downTo(to: Double): DoubleProgression {
return DoubleProgression(this.toDouble(), to, -1.0) return DoubleProgression(this.toDouble(), to, -1.0)
} }
@@ -336,6 +366,8 @@ public infix fun Byte.downTo(to: Double): DoubleProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Short.downTo(to: Double): DoubleProgression { public infix fun Short.downTo(to: Double): DoubleProgression {
return DoubleProgression(this.toDouble(), to, -1.0) return DoubleProgression(this.toDouble(), to, -1.0)
} }
@@ -344,6 +376,8 @@ public infix fun Short.downTo(to: Double): DoubleProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Double.downTo(to: Double): DoubleProgression { public infix fun Double.downTo(to: Double): DoubleProgression {
return DoubleProgression(this, to, -1.0) return DoubleProgression(this, to, -1.0)
} }
@@ -352,6 +386,8 @@ public infix fun Double.downTo(to: Double): DoubleProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Float.downTo(to: Double): DoubleProgression { public infix fun Float.downTo(to: Double): DoubleProgression {
return DoubleProgression(this.toDouble(), to, -1.0) return DoubleProgression(this.toDouble(), to, -1.0)
} }
@@ -360,6 +396,8 @@ public infix fun Float.downTo(to: Double): DoubleProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Int.downTo(to: Float): FloatProgression { public infix fun Int.downTo(to: Float): FloatProgression {
return FloatProgression(this.toFloat(), to, -1.0F) return FloatProgression(this.toFloat(), to, -1.0F)
} }
@@ -368,6 +406,8 @@ public infix fun Int.downTo(to: Float): FloatProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Long.downTo(to: Float): FloatProgression { public infix fun Long.downTo(to: Float): FloatProgression {
return FloatProgression(this.toFloat(), to, -1.0F) return FloatProgression(this.toFloat(), to, -1.0F)
} }
@@ -376,6 +416,8 @@ public infix fun Long.downTo(to: Float): FloatProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Byte.downTo(to: Float): FloatProgression { public infix fun Byte.downTo(to: Float): FloatProgression {
return FloatProgression(this.toFloat(), to, -1.0F) return FloatProgression(this.toFloat(), to, -1.0F)
} }
@@ -384,6 +426,8 @@ public infix fun Byte.downTo(to: Float): FloatProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Short.downTo(to: Float): FloatProgression { public infix fun Short.downTo(to: Float): FloatProgression {
return FloatProgression(this.toFloat(), to, -1.0F) return FloatProgression(this.toFloat(), to, -1.0F)
} }
@@ -392,6 +436,8 @@ public infix fun Short.downTo(to: Float): FloatProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Double.downTo(to: Float): DoubleProgression { public infix fun Double.downTo(to: Float): DoubleProgression {
return DoubleProgression(this, to.toDouble(), -1.0) return DoubleProgression(this, to.toDouble(), -1.0)
} }
@@ -400,6 +446,8 @@ public infix fun Double.downTo(to: Float): DoubleProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Float.downTo(to: Float): FloatProgression { public infix fun Float.downTo(to: Float): FloatProgression {
return FloatProgression(this, to, -1.0F) return FloatProgression(this, to, -1.0F)
} }
@@ -440,6 +488,8 @@ public infix fun Short.downTo(to: Int): IntProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Double.downTo(to: Int): DoubleProgression { public infix fun Double.downTo(to: Int): DoubleProgression {
return DoubleProgression(this, to.toDouble(), -1.0) return DoubleProgression(this, to.toDouble(), -1.0)
} }
@@ -448,6 +498,8 @@ public infix fun Double.downTo(to: Int): DoubleProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Float.downTo(to: Int): FloatProgression { public infix fun Float.downTo(to: Int): FloatProgression {
return FloatProgression(this, to.toFloat(), -1.0F) return FloatProgression(this, to.toFloat(), -1.0F)
} }
@@ -488,6 +540,8 @@ public infix fun Short.downTo(to: Long): LongProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Double.downTo(to: Long): DoubleProgression { public infix fun Double.downTo(to: Long): DoubleProgression {
return DoubleProgression(this, to.toDouble(), -1.0) return DoubleProgression(this, to.toDouble(), -1.0)
} }
@@ -496,6 +550,8 @@ public infix fun Double.downTo(to: Long): DoubleProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Float.downTo(to: Long): FloatProgression { public infix fun Float.downTo(to: Long): FloatProgression {
return FloatProgression(this, to.toFloat(), -1.0F) return FloatProgression(this, to.toFloat(), -1.0F)
} }
@@ -536,6 +592,8 @@ public infix fun Short.downTo(to: Short): ShortProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Double.downTo(to: Short): DoubleProgression { public infix fun Double.downTo(to: Short): DoubleProgression {
return DoubleProgression(this, to.toDouble(), -1.0) return DoubleProgression(this, to.toDouble(), -1.0)
} }
@@ -544,6 +602,8 @@ public infix fun Double.downTo(to: Short): DoubleProgression {
* Returns a progression from this value down to the specified [to] value with the increment -1. * Returns a progression from this value down to the specified [to] value with the increment -1.
* The [to] value has to be less than this value. * The [to] value has to be less than this value.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun Float.downTo(to: Short): FloatProgression { public infix fun Float.downTo(to: Short): FloatProgression {
return FloatProgression(this, to.toFloat(), -1.0F) return FloatProgression(this, to.toFloat(), -1.0F)
} }
@@ -562,20 +622,6 @@ public fun CharProgression.reversed(): CharProgression {
return CharProgression(end, start, -increment) return CharProgression(end, start, -increment)
} }
/**
* Returns a progression that goes over the same range in the opposite direction with the same step.
*/
public fun DoubleProgression.reversed(): DoubleProgression {
return DoubleProgression(end, start, -increment)
}
/**
* Returns a progression that goes over the same range in the opposite direction with the same step.
*/
public fun FloatProgression.reversed(): FloatProgression {
return FloatProgression(end, start, -increment)
}
/** /**
* Returns a progression that goes over the same range in the opposite direction with the same step. * Returns a progression that goes over the same range in the opposite direction with the same step.
*/ */
@@ -611,20 +657,6 @@ public fun CharRange.reversed(): CharProgression {
return CharProgression(end, start, -1) return CharProgression(end, start, -1)
} }
/**
* Returns a progression that goes over this range in reverse direction.
*/
public fun DoubleRange.reversed(): DoubleProgression {
return DoubleProgression(end, start, -1.0)
}
/**
* Returns a progression that goes over this range in reverse direction.
*/
public fun FloatRange.reversed(): FloatProgression {
return FloatProgression(end, start, -1.0f)
}
/** /**
* Returns a progression that goes over this range in reverse direction. * Returns a progression that goes over this range in reverse direction.
*/ */
@@ -646,6 +678,42 @@ public fun ShortRange.reversed(): ShortProgression {
return ShortProgression(end, start, -1) return ShortProgression(end, start, -1)
} }
/**
* Returns a progression that goes over the same range in the opposite direction with the same step.
*/
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public fun DoubleProgression.reversed(): DoubleProgression {
return DoubleProgression(end, start, -increment)
}
/**
* Returns a progression that goes over the same range in the opposite direction with the same step.
*/
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public fun FloatProgression.reversed(): FloatProgression {
return FloatProgression(end, start, -increment)
}
/**
* Returns a progression that goes over this range in reverse direction.
*/
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public fun DoubleRange.reversed(): DoubleProgression {
return DoubleProgression(end, start, -1.0)
}
/**
* Returns a progression that goes over this range in reverse direction.
*/
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public fun FloatRange.reversed(): FloatProgression {
return FloatProgression(end, start, -1.0f)
}
/** /**
* Returns a progression that goes over the same range with the given step. * Returns a progression that goes over the same range with the given step.
*/ */
@@ -662,22 +730,6 @@ public infix fun CharProgression.step(step: Int): CharProgression {
return CharProgression(start, end, if (increment > 0) step else -step) return CharProgression(start, end, if (increment > 0) step else -step)
} }
/**
* Returns a progression that goes over the same range with the given step.
*/
public infix fun DoubleProgression.step(step: Double): DoubleProgression {
checkStepIsPositive(step > 0, step)
return DoubleProgression(start, end, if (increment > 0) step else -step)
}
/**
* Returns a progression that goes over the same range with the given step.
*/
public infix fun FloatProgression.step(step: Float): FloatProgression {
checkStepIsPositive(step > 0, step)
return FloatProgression(start, end, if (increment > 0) step else -step)
}
/** /**
* Returns a progression that goes over the same range with the given step. * Returns a progression that goes over the same range with the given step.
*/ */
@@ -718,24 +770,6 @@ public infix fun CharRange.step(step: Int): CharProgression {
return CharProgression(start, end, step) return CharProgression(start, end, step)
} }
/**
* Returns a progression that goes over this range with given step.
*/
public infix fun DoubleRange.step(step: Double): DoubleProgression {
if (step.isNaN()) throw IllegalArgumentException("Step must not be NaN.")
checkStepIsPositive(step > 0, step)
return DoubleProgression(start, end, step)
}
/**
* Returns a progression that goes over this range with given step.
*/
public infix fun FloatRange.step(step: Float): FloatProgression {
if (step.isNaN()) throw IllegalArgumentException("Step must not be NaN.")
checkStepIsPositive(step > 0, step)
return FloatProgression(start, end, step)
}
/** /**
* Returns a progression that goes over this range with given step. * Returns a progression that goes over this range with given step.
*/ */
@@ -760,6 +794,48 @@ public infix fun ShortRange.step(step: Int): ShortProgression {
return ShortProgression(start, end, step) return ShortProgression(start, end, step)
} }
/**
* Returns a progression that goes over the same range with the given step.
*/
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun DoubleProgression.step(step: Double): DoubleProgression {
checkStepIsPositive(step > 0, step)
return DoubleProgression(start, end, if (increment > 0) step else -step)
}
/**
* Returns a progression that goes over the same range with the given step.
*/
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun FloatProgression.step(step: Float): FloatProgression {
checkStepIsPositive(step > 0, step)
return FloatProgression(start, end, if (increment > 0) step else -step)
}
/**
* Returns a progression that goes over this range with given step.
*/
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun DoubleRange.step(step: Double): DoubleProgression {
if (step.isNaN()) throw IllegalArgumentException("Step must not be NaN.")
checkStepIsPositive(step > 0, step)
return DoubleProgression(start, end, step)
}
/**
* Returns a progression that goes over this range with given step.
*/
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public infix fun FloatRange.step(step: Float): FloatProgression {
if (step.isNaN()) throw IllegalArgumentException("Step must not be NaN.")
checkStepIsPositive(step > 0, step)
return FloatProgression(start, end, step)
}
/** /**
* Returns a range from this value up to but excluding the specified [to] value. * Returns a range from this value up to but excluding the specified [to] value.
*/ */
@@ -1143,15 +1219,6 @@ public fun Short.coerceIn(minimumValue: Short?, maximumValue: Short?): Short {
return this return this
} }
/**
* Ensures that this value lies in the specified [range].
* @return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end.
*/
public fun <T: Comparable<T>> T.coerceIn(range: Range<T>): T {
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
return if (this < range.start) range.start else if (this > range.end) range.end else this
}
/** /**
* Ensures that this value lies in the specified [range]. * Ensures that this value lies in the specified [range].
* @return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end. * @return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end.
@@ -1161,24 +1228,6 @@ public fun Byte.coerceIn(range: Range<Byte>): Byte {
return if (this < range.start) range.start else if (this > range.end) range.end else this return if (this < range.start) range.start else if (this > range.end) range.end else this
} }
/**
* Ensures that this value lies in the specified [range].
* @return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end.
*/
public fun Double.coerceIn(range: Range<Double>): Double {
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
return if (this < range.start) range.start else if (this > range.end) range.end else this
}
/**
* Ensures that this value lies in the specified [range].
* @return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end.
*/
public fun Float.coerceIn(range: Range<Float>): Float {
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
return if (this < range.start) range.start else if (this > range.end) range.end else this
}
/** /**
* Ensures that this value lies in the specified [range]. * Ensures that this value lies in the specified [range].
* @return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end. * @return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end.
@@ -1206,3 +1255,33 @@ public fun Short.coerceIn(range: Range<Short>): Short {
return if (this < range.start) range.start else if (this > range.end) range.end else this return if (this < range.start) range.start else if (this > range.end) range.end else this
} }
/**
* Ensures that this value lies in the specified [range].
* @return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end.
*/
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
public fun <T: Comparable<T>> T.coerceIn(range: Range<T>): T {
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
return if (this < range.start) range.start else if (this > range.end) range.end else this
}
/**
* Ensures that this value lies in the specified [range].
* @return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end.
*/
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
public fun Double.coerceIn(range: Range<Double>): Double {
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
return if (this < range.start) range.start else if (this > range.end) range.end else this
}
/**
* Ensures that this value lies in the specified [range].
* @return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end.
*/
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
public fun Float.coerceIn(range: Range<Float>): Float {
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
return if (this < range.start) range.start else if (this > range.end) range.end else this
}
@@ -5,6 +5,7 @@ package kotlin
/** /**
* Represents a range of [Comparable] values. * Represents a range of [Comparable] values.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
public class ComparableRange<T: Comparable<T>> ( public class ComparableRange<T: Comparable<T>> (
override val start: T, override val start: T,
override val end: T override val end: T
@@ -13,6 +14,7 @@ public class ComparableRange<T: Comparable<T>> (
return start <= item && item <= end return start <= item && item <= end
} }
@Suppress("DEPRECATION_ERROR")
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
return other is ComparableRange<*> && (isEmpty() && other.isEmpty() || return other is ComparableRange<*> && (isEmpty() && other.isEmpty() ||
start == other.start && end == other.end) start == other.start && end == other.end)
@@ -29,6 +31,8 @@ public class ComparableRange<T: Comparable<T>> (
* Creates a range from this [Comparable] value to the specified [that] value. This value * Creates a range from this [Comparable] value to the specified [that] value. This value
* needs to be smaller than [that] value, otherwise the returned range will be empty. * needs to be smaller than [that] value, otherwise the returned range will be empty.
*/ */
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public operator fun <T: Comparable<T>> T.rangeTo(that: T): ComparableRange<T> { public operator fun <T: Comparable<T>> T.rangeTo(that: T): ComparableRange<T> {
return ComparableRange(this, that) return ComparableRange(this, that)
} }
@@ -1,3 +1,4 @@
@file: Suppress("DEPRECATION_ERROR")
package language package language
import java.lang.Integer.MAX_VALUE as MaxI import java.lang.Integer.MAX_VALUE as MaxI
@@ -1,3 +1,4 @@
@file: Suppress("DEPRECATION_ERROR")
package language package language
import org.junit.Test as test import org.junit.Test as test
@@ -1,3 +1,4 @@
@file: Suppress("DEPRECATION_ERROR")
package language package language
import java.lang.Double as jDouble import java.lang.Double as jDouble
@@ -1,3 +1,4 @@
@file: Suppress("DEPRECATION_ERROR")
package language package language
import kotlin.test.* import kotlin.test.*
@@ -65,6 +65,7 @@ class CoercionTest {
} }
@Test @Test
@Suppress("DEPRECATION_ERROR")
fun coercionsDouble() { fun coercionsDouble() {
expect(5.0) { 5.0.coerceAtLeast(1.0) } expect(5.0) { 5.0.coerceAtLeast(1.0) }
expect(5.0) { 1.0.coerceAtLeast(5.0) } expect(5.0) { 1.0.coerceAtLeast(5.0) }
@@ -88,6 +89,7 @@ class CoercionTest {
} }
@Test @Test
@Suppress("DEPRECATION_ERROR")
fun coercionsComparable() { fun coercionsComparable() {
val v = 0..10 map { ComparableNumber(it) } val v = 0..10 map { ComparableNumber(it) }
@@ -47,10 +47,30 @@ fun comparables(): List<GenericFunction> {
} }
} }
templates add f("coerceIn(range: Range<T>)") {
sourceFile(SourceFile.Ranges)
only(Primitives)
only(numericPrimitives.filter { it.isIntegral() })
returns("SELF")
doc {
"""
Ensures that this value lies in the specified [range].
@return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end.
"""
}
body {
"""
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: ${'$'}range.")
return if (this < range.start) range.start else if (this > range.end) range.end else this
"""
}
}
templates add f("coerceIn(range: Range<T>)") { templates add f("coerceIn(range: Range<T>)") {
sourceFile(SourceFile.Ranges) sourceFile(SourceFile.Ranges)
only(Primitives, Generic) only(Primitives, Generic)
only(numericPrimitives) only(numericPrimitives.filterNot { it.isIntegral() })
returns("SELF") returns("SELF")
typeParam("T: Comparable<T>") typeParam("T: Comparable<T>")
doc { doc {
@@ -60,6 +80,7 @@ fun comparables(): List<GenericFunction> {
@return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end. @return this value if it's in the [range], or range.start if this value is less than range.start, or range.end if this value is greater than range.end.
""" """
} }
deprecate(Deprecation("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR))
body { body {
""" """
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: ${'$'}range.") if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: ${'$'}range.")
@@ -8,7 +8,7 @@ fun ranges(): List<GenericFunction> {
templates add f("reversed()") { templates add f("reversed()") {
only(RangesOfPrimitives, ProgressionsOfPrimitives) only(RangesOfPrimitives, ProgressionsOfPrimitives)
exclude(PrimitiveType.Boolean) only(PrimitiveType.integralPrimitives)
doc(ProgressionsOfPrimitives) { "Returns a progression that goes over the same range in the opposite direction with the same step." } doc(ProgressionsOfPrimitives) { "Returns a progression that goes over the same range in the opposite direction with the same step." }
doc(RangesOfPrimitives) { "Returns a progression that goes over this range in reverse direction." } doc(RangesOfPrimitives) { "Returns a progression that goes over this range in reverse direction." }
returns("TProgression") returns("TProgression")
@@ -20,11 +20,27 @@ fun ranges(): List<GenericFunction> {
} }
} }
templates add f("reversed()") {
only(RangesOfPrimitives, ProgressionsOfPrimitives)
only(defaultPrimitives - PrimitiveType.Boolean - PrimitiveType.integralPrimitives)
doc(ProgressionsOfPrimitives) { "Returns a progression that goes over the same range in the opposite direction with the same step." }
doc(RangesOfPrimitives) { "Returns a progression that goes over this range in reverse direction." }
returns("TProgression")
deprecate(Deprecation("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR))
annotations("""@Suppress("DEPRECATION_ERROR")""")
body(RangesOfPrimitives) {
"return TProgression(end, start, -ONE)"
}
body(ProgressionsOfPrimitives) {
"return TProgression(end, start, -increment)"
}
}
templates add f("step(step: SUM)") { templates add f("step(step: SUM)") {
infix(true) infix(true)
only(RangesOfPrimitives, ProgressionsOfPrimitives) only(RangesOfPrimitives, ProgressionsOfPrimitives)
exclude(PrimitiveType.Boolean) only(PrimitiveType.integralPrimitives)
doc(ProgressionsOfPrimitives) { "Returns a progression that goes over the same range with the given step." } doc(ProgressionsOfPrimitives) { "Returns a progression that goes over the same range with the given step." }
doc(RangesOfPrimitives) { "Returns a progression that goes over this range with given step." } doc(RangesOfPrimitives) { "Returns a progression that goes over this range with given step." }
returns("TProgression") returns("TProgression")
@@ -34,6 +50,30 @@ fun ranges(): List<GenericFunction> {
return TProgression(start, end, step) return TProgression(start, end, step)
""" """
} }
body(ProgressionsOfPrimitives) {
"""
checkStepIsPositive(step > 0, step)
return TProgression(start, end, if (increment > 0) step else -step)
"""
}
}
templates add f("step(step: SUM)") {
infix(true)
only(RangesOfPrimitives, ProgressionsOfPrimitives)
only(defaultPrimitives - PrimitiveType.Boolean - PrimitiveType.integralPrimitives)
doc(ProgressionsOfPrimitives) { "Returns a progression that goes over the same range with the given step." }
doc(RangesOfPrimitives) { "Returns a progression that goes over this range with given step." }
returns("TProgression")
deprecate(Deprecation("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR))
annotations("""@Suppress("DEPRECATION_ERROR")""")
body(RangesOfPrimitives) {
"""
checkStepIsPositive(step > 0, step)
return TProgression(start, end, step)
"""
}
bodyForTypes(RangesOfPrimitives, PrimitiveType.Float, PrimitiveType.Double) { bodyForTypes(RangesOfPrimitives, PrimitiveType.Float, PrimitiveType.Double) {
""" """
if (step.isNaN()) throw IllegalArgumentException("Step must not be NaN.") if (step.isNaN()) throw IllegalArgumentException("Step must not be NaN.")
@@ -66,6 +106,11 @@ fun ranges(): List<GenericFunction> {
""" """
} }
if (!fromType.isIntegral() || !toType.isIntegral()) {
deprecate(Deprecation("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR))
annotations("""@Suppress("DEPRECATION_ERROR")""")
}
val fromExpr = if (elementType == fromType) "this" else "this.to$elementType()" val fromExpr = if (elementType == fromType) "this" else "this.to$elementType()"
val toExpr = if (elementType == toType) "to" else "to.to$elementType()" val toExpr = if (elementType == toType) "to" else "to.to$elementType()"
val incrementExpr = when (elementType) { val incrementExpr = when (elementType) {
@@ -101,6 +146,11 @@ fun ranges(): List<GenericFunction> {
""" """
} }
if (!fromType.isIntegral() || !toType.isIntegral()) {
deprecate(Deprecation("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR))
annotations("""@Suppress("DEPRECATION_ERROR")""")
}
val fromExpr = if (elementType == fromType) "this" else "this.to$elementType()" val fromExpr = if (elementType == fromType) "this" else "this.to$elementType()"
if (elementType == toType) { if (elementType == toType) {
@@ -129,7 +179,12 @@ fun ranges(): List<GenericFunction> {
fun contains(rangeType: PrimitiveType, itemType: PrimitiveType) = f("contains(item: $itemType)") { fun contains(rangeType: PrimitiveType, itemType: PrimitiveType) = f("contains(item: $itemType)") {
operator(true) operator(true)
assert(rangeType.isNumeric() != itemType.isNumeric()) if (!rangeType.isIntegral()) {
deprecate(Deprecation("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.ERROR))
annotations("""@Suppress("DEPRECATION_ERROR")""")
}
check(rangeType.isNumeric() == itemType.isNumeric()) { "Require rangeType and itemType both be numeric or both not, got: $rangeType, $itemType" }
only(Ranges) only(Ranges)
onlyPrimitives(Ranges, rangeType) onlyPrimitives(Ranges, rangeType)
platformName("${rangeType.name.decapitalize()}RangeContains") platformName("${rangeType.name.decapitalize()}RangeContains")