Drop Ranges, Progressions, ProgressionIterators for Double and Float.

Undeprecate generic Comparable.rangeTo, but return private implementation instead.
Undeprecate contains and coerceIn for generic ranges.
This commit is contained in:
Ilya Gorbunov
2015-11-06 18:22:31 +03:00
parent 4d2f9b82da
commit 6bac3e1986
54 changed files with 30 additions and 1630 deletions
-40
View File
@@ -144,10 +144,6 @@ public class Byte private () : Number, Comparable<Byte> {
public operator fun rangeTo(other: Int): IntRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Long): LongRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Float): FloatRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Double): DoubleRange
public override fun toByte(): Byte
public override fun toChar(): Char
@@ -284,10 +280,6 @@ public class Short private () : Number, Comparable<Short> {
public operator fun rangeTo(other: Int): IntRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Long): LongRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Float): FloatRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Double): DoubleRange
public override fun toByte(): Byte
public override fun toChar(): Char
@@ -424,10 +416,6 @@ public class Int private () : Number, Comparable<Int> {
public operator fun rangeTo(other: Int): IntRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Long): LongRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Float): FloatRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Double): DoubleRange
/** Shifts this value left by [bits]. */
public infix fun shl(bitCount: Int): Int
@@ -579,10 +567,6 @@ public class Long private () : Number, Comparable<Long> {
public operator fun rangeTo(other: Int): LongRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Long): LongRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Float): FloatRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Double): DoubleRange
/** Shifts this value left by [bits]. */
public infix fun shl(bitCount: Int): Long
@@ -726,18 +710,6 @@ public class Float private () : Number, Comparable<Float> {
/** Returns the negative of this value. */
public operator fun unaryMinus(): Float
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Byte): FloatRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Short): FloatRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Int): FloatRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Long): FloatRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Float): FloatRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Double): DoubleRange
public override fun toByte(): Byte
public override fun toChar(): Char
@@ -866,18 +838,6 @@ public class Double private () : Number, Comparable<Double> {
/** Returns the negative of this value. */
public operator fun unaryMinus(): Double
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Byte): DoubleRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Short): DoubleRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Int): DoubleRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Long): DoubleRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Float): DoubleRange
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Double): DoubleRange
public override fun toByte(): Byte
public override fun toChar(): Char
@@ -135,37 +135,3 @@ internal class LongProgressionIterator(start: Long, end: Long, val increment: Lo
}
}
/**
* An iterator over a progression of values of type `Float`.
* @property increment the number by which the value is incremented on each step.
*/
@Deprecated("This progression implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.WARNING)
internal class FloatProgressionIterator(start: Float, val end: Float, val increment: Float) : FloatIterator() {
private var next = start
override fun hasNext(): Boolean = if (increment > 0) next <= end else next >= end
override fun nextFloat(): Float {
val value = next
next += increment
return value
}
}
/**
* An iterator over a progression of values of type `Double`.
* @property increment the number by which the value is incremented on each step.
*/
@Deprecated("This progression implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.WARNING)
internal class DoubleProgressionIterator(start: Double, val end: Double, val increment: Double) : DoubleIterator() {
private var next = start
override fun hasNext(): Boolean = if (increment > 0) next <= end else next >= end
override fun nextDouble(): Double {
val value = next
next += increment
return value
}
}
-77
View File
@@ -310,80 +310,3 @@ public open class LongProgression
}
}
/**
* A progression of values of type `Float`.
*/
@Deprecated("This progression implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.WARNING)
public open class FloatProgression(
override val start: Float,
val endInclusive: Float,
override val increment: Float
) : Progression<Float> /*, Iterable<Float> */ {
init {
if (java.lang.Float.isNaN(increment)) throw IllegalArgumentException("Increment must be not NaN")
if (increment == 0.0f) throw IllegalArgumentException("Increment must be non-zero")
}
/**
* The end value of the progression (inclusive).
*/
@Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive"))
public override val end: Float get() = endInclusive
override fun iterator(): FloatIterator = FloatProgressionIterator(start, endInclusive, increment)
/** Checks if the progression is empty. */
public open fun isEmpty(): Boolean = if (increment > 0) start > endInclusive else start < endInclusive
override fun equals(other: Any?): Boolean =
other is FloatProgression && (isEmpty() && other.isEmpty() ||
java.lang.Float.compare(start, other.start) == 0 && java.lang.Float.compare(endInclusive, other.endInclusive) == 0 && java.lang.Float.compare(increment, other.increment) == 0)
override fun hashCode(): Int =
if (isEmpty()) -1 else (31 * (31 * java.lang.Float.floatToIntBits(start) + java.lang.Float.floatToIntBits(endInclusive)) + java.lang.Float.floatToIntBits(increment))
override fun toString(): String = if (increment > 0) "$start..$endInclusive step $increment" else "$start downTo $endInclusive step ${-increment}"
}
/**
* A progression of values of type `Double`.
*/
@Deprecated("This progression implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.WARNING)
public open class DoubleProgression(
override val start: Double,
val endInclusive: Double,
override val increment: Double
) : Progression<Double> /*, Iterable<Double> */ {
init {
if (java.lang.Double.isNaN(increment)) throw IllegalArgumentException("Increment must be not NaN")
if (increment == 0.0) throw IllegalArgumentException("Increment must be non-zero")
}
/**
* The end value of the progression (inclusive).
*/
@Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive"))
public override val end: Double get() = endInclusive
override fun iterator(): DoubleIterator = DoubleProgressionIterator(start, endInclusive, increment)
/** Checks if the progression is empty. */
public open fun isEmpty(): Boolean = if (increment > 0) start > endInclusive else start < endInclusive
override fun equals(other: Any?): Boolean =
other is DoubleProgression && (isEmpty() && other.isEmpty() ||
java.lang.Double.compare(start, other.start) == 0 && java.lang.Double.compare(endInclusive, other.endInclusive) == 0 && java.lang.Double.compare(increment, other.increment) == 0)
override fun hashCode(): Int {
if (isEmpty()) return -1
var temp = java.lang.Double.doubleToLongBits(start)
var result = (temp xor (temp ushr 32))
temp = java.lang.Double.doubleToLongBits(endInclusive)
result = 31 * result + (temp xor (temp ushr 32))
temp = java.lang.Double.doubleToLongBits(increment)
return (31 * result + (temp xor (temp ushr 32))).toInt()
}
override fun toString(): String = if (increment > 0) "$start..$endInclusive step $increment" else "$start downTo $endInclusive step ${-increment}"
}
-61
View File
@@ -165,64 +165,3 @@ public class LongRange(start: Long, endInclusive: Long) : LongProgression(start,
}
}
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.WARNING)
@Suppress("DEPRECATION_ERROR")
/**
* A range of values of type `Float`.
*/
public class FloatRange(start: Float, endInclusive: Float) : FloatProgression(start, endInclusive, 1.0f), ClosedRange<Float> {
@Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive"))
override val end: Float get() = endInclusive
override fun contains(item: Float): Boolean = start <= item && item <= endInclusive
override fun isEmpty(): Boolean = start > endInclusive
override fun equals(other: Any?): Boolean =
other is FloatRange && (isEmpty() && other.isEmpty() ||
java.lang.Float.compare(start, other.start) == 0 && java.lang.Float.compare(endInclusive, other.endInclusive) == 0)
override fun hashCode(): Int =
if (isEmpty()) -1 else (31 * java.lang.Float.floatToIntBits(start) + java.lang.Float.floatToIntBits(endInclusive))
override fun toString(): String = "$start..$endInclusive"
companion object {
/** An empty range of values of type Float. */
public val EMPTY: FloatRange = FloatRange(1.0f, 0.0f)
}
}
@Deprecated("This range implementation has unclear semantics and will be removed soon.", level = DeprecationLevel.WARNING)
@Suppress("DEPRECATION_ERROR")
/**
* A range of values of type `Double`.
*/
public class DoubleRange(start: Double, endInclusive: Double) : DoubleProgression(start, endInclusive, 1.0), ClosedRange<Double> {
@Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive"))
override val end: Double get() = endInclusive
override fun contains(item: Double): Boolean = start <= item && item <= endInclusive
override fun isEmpty(): Boolean = start > endInclusive
override fun equals(other: Any?): Boolean =
other is DoubleRange && (isEmpty() && other.isEmpty() ||
java.lang.Double.compare(start, other.start) == 0 && java.lang.Double.compare(endInclusive, other.endInclusive) == 0)
override fun hashCode(): Int {
if (isEmpty()) return -1
var temp = java.lang.Double.doubleToLongBits(start)
val result = (temp xor (temp ushr 32))
temp = java.lang.Double.doubleToLongBits(endInclusive)
return (31 * result + (temp xor (temp ushr 32))).toInt()
}
override fun toString(): String = "$start..$endInclusive"
companion object {
/** An empty range of values of type Double. */
public val EMPTY: DoubleRange = DoubleRange(1.0, 0.0)
}
}