Drop deprecated primitive ranges and progressions: for Byte and Short
This commit is contained in:
@@ -18,29 +18,6 @@
|
||||
|
||||
package kotlin.ranges
|
||||
|
||||
/**
|
||||
* An iterator over a progression of values of type `Byte`.
|
||||
* @property step the number by which the value is incremented on each step.
|
||||
*/
|
||||
internal class ByteProgressionIterator(first: Byte, last: Byte, val step: Int) : ByteIterator() {
|
||||
private var next = first.toInt()
|
||||
private val finalElement = last.toInt()
|
||||
private var hasNext: Boolean = if (step > 0) first <= last else first >= last
|
||||
|
||||
override fun hasNext(): Boolean = hasNext
|
||||
|
||||
override fun nextByte(): Byte {
|
||||
val value = next
|
||||
if (value == finalElement) {
|
||||
hasNext = false
|
||||
}
|
||||
else {
|
||||
next += step
|
||||
}
|
||||
return value.toByte()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An iterator over a progression of values of type `Char`.
|
||||
* @property step the number by which the value is incremented on each step.
|
||||
@@ -64,29 +41,6 @@ internal class CharProgressionIterator(first: Char, last: Char, val step: Int) :
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An iterator over a progression of values of type `Short`.
|
||||
* @property step the number by which the value is incremented on each step.
|
||||
*/
|
||||
internal class ShortProgressionIterator(first: Short, last: Short, val step: Int) : ShortIterator() {
|
||||
private var next = first.toInt()
|
||||
private val finalElement = last.toInt()
|
||||
private var hasNext: Boolean = if (step > 0) first <= last else first >= last
|
||||
|
||||
override fun hasNext(): Boolean = hasNext
|
||||
|
||||
override fun nextShort(): Short {
|
||||
val value = next
|
||||
if (value == finalElement) {
|
||||
hasNext = false
|
||||
}
|
||||
else {
|
||||
next += step
|
||||
}
|
||||
return value.toShort()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An iterator over a progression of values of type `Int`.
|
||||
* @property step the number by which the value is incremented on each step.
|
||||
|
||||
@@ -20,75 +20,6 @@ package kotlin.ranges
|
||||
|
||||
import kotlin.internal.getProgressionLastElement
|
||||
|
||||
@Deprecated("Use IntProgression instead.", ReplaceWith("IntProgression"), level = DeprecationLevel.WARNING)
|
||||
/**
|
||||
* A progression of values of type `Byte`.
|
||||
*/
|
||||
public open class ByteProgression
|
||||
@Deprecated("This constructor will become private soon. Use ByteProgression.fromClosedRange() instead.", ReplaceWith("ByteProgression.fromClosedRange(start, endInclusive, step)"))
|
||||
public constructor
|
||||
(
|
||||
start: Byte,
|
||||
endInclusive: Byte,
|
||||
step: Int
|
||||
) : Progression<Byte> /*, Iterable<Byte> */ {
|
||||
init {
|
||||
if (step == 0) throw IllegalArgumentException("Step must be non-zero")
|
||||
}
|
||||
|
||||
/**
|
||||
* The first element in the progression.
|
||||
*/
|
||||
public val first: Byte = start
|
||||
|
||||
/**
|
||||
* The last element in the progression.
|
||||
*/
|
||||
public val last: Byte = getProgressionLastElement(start.toInt(), endInclusive.toInt(), step).toByte()
|
||||
|
||||
/**
|
||||
* The step of the progression.
|
||||
*/
|
||||
public val step: Int = step
|
||||
|
||||
@Deprecated("Use 'first' property instead.", ReplaceWith("first"))
|
||||
public override val start: Byte get() = first
|
||||
|
||||
/**
|
||||
* The end value of the progression (inclusive).
|
||||
*/
|
||||
@Deprecated("Use 'last' property instead.")
|
||||
public override val end: Byte = endInclusive
|
||||
|
||||
@Deprecated("Use 'step' property instead.", ReplaceWith("step"))
|
||||
public override val increment: Int get() = step
|
||||
|
||||
|
||||
override fun iterator(): ByteIterator = ByteProgressionIterator(first, last, step)
|
||||
|
||||
/** Checks if the progression is empty. */
|
||||
public open fun isEmpty(): Boolean = if (step > 0) first > last else first < last
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is ByteProgression && (isEmpty() && other.isEmpty() ||
|
||||
first == other.first && last == other.last && step == other.step)
|
||||
|
||||
override fun hashCode(): Int =
|
||||
if (isEmpty()) -1 else (31 * (31 * first.toInt() + last.toInt()) + step)
|
||||
|
||||
override fun toString(): String = if (step > 0) "$first..$last step $step" else "$first downTo $last step ${-step}"
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Creates ByteProgression within the specified bounds of a closed range.
|
||||
|
||||
* The progression starts with the [rangeStart] value and goes toward the [rangeEnd] value not excluding it, with the specified [step].
|
||||
* In order to go backwards the [step] must be negative.
|
||||
*/
|
||||
public fun fromClosedRange(rangeStart: Byte, rangeEnd: Byte, step: Int): ByteProgression = ByteProgression(rangeStart, rangeEnd, step)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A progression of values of type `Char`.
|
||||
*/
|
||||
@@ -157,75 +88,6 @@ public open class CharProgression
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Use IntProgression instead.", ReplaceWith("IntProgression"), level = DeprecationLevel.WARNING)
|
||||
/**
|
||||
* A progression of values of type `Short`.
|
||||
*/
|
||||
public open class ShortProgression
|
||||
@Deprecated("This constructor will become private soon. Use ShortProgression.fromClosedRange() instead.", ReplaceWith("ShortProgression.fromClosedRange(start, endInclusive, step)"))
|
||||
public constructor
|
||||
(
|
||||
start: Short,
|
||||
endInclusive: Short,
|
||||
step: Int
|
||||
) : Progression<Short> /*, Iterable<Short> */ {
|
||||
init {
|
||||
if (step == 0) throw IllegalArgumentException("Step must be non-zero")
|
||||
}
|
||||
|
||||
/**
|
||||
* The first element in the progression.
|
||||
*/
|
||||
public val first: Short = start
|
||||
|
||||
/**
|
||||
* The last element in the progression.
|
||||
*/
|
||||
public val last: Short = getProgressionLastElement(start.toInt(), endInclusive.toInt(), step).toShort()
|
||||
|
||||
/**
|
||||
* The step of the progression.
|
||||
*/
|
||||
public val step: Int = step
|
||||
|
||||
@Deprecated("Use 'first' property instead.", ReplaceWith("first"))
|
||||
public override val start: Short get() = first
|
||||
|
||||
/**
|
||||
* The end value of the progression (inclusive).
|
||||
*/
|
||||
@Deprecated("Use 'last' property instead.")
|
||||
public override val end: Short = endInclusive
|
||||
|
||||
@Deprecated("Use 'step' property instead.", ReplaceWith("step"))
|
||||
public override val increment: Int get() = step
|
||||
|
||||
|
||||
override fun iterator(): ShortIterator = ShortProgressionIterator(first, last, step)
|
||||
|
||||
/** Checks if the progression is empty. */
|
||||
public open fun isEmpty(): Boolean = if (step > 0) first > last else first < last
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is ShortProgression && (isEmpty() && other.isEmpty() ||
|
||||
first == other.first && last == other.last && step == other.step)
|
||||
|
||||
override fun hashCode(): Int =
|
||||
if (isEmpty()) -1 else (31 * (31 * first.toInt() + last.toInt()) + step)
|
||||
|
||||
override fun toString(): String = if (step > 0) "$first..$last step $step" else "$first downTo $last step ${-step}"
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Creates ShortProgression within the specified bounds of a closed range.
|
||||
|
||||
* The progression starts with the [rangeStart] value and goes toward the [rangeEnd] value not excluding it, with the specified [step].
|
||||
* In order to go backwards the [step] must be negative.
|
||||
*/
|
||||
public fun fromClosedRange(rangeStart: Short, rangeEnd: Short, step: Int): ShortProgression = ShortProgression(rangeStart, rangeEnd, step)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A progression of values of type `Int`.
|
||||
*/
|
||||
|
||||
@@ -18,36 +18,6 @@
|
||||
|
||||
package kotlin.ranges
|
||||
|
||||
@Deprecated("Use IntRange instead.", ReplaceWith("IntRange"), level = DeprecationLevel.WARNING)
|
||||
/**
|
||||
* A range of values of type `Byte`.
|
||||
*/
|
||||
public class ByteRange(start: Byte, endInclusive: Byte) : ByteProgression(start, endInclusive, 1), ClosedRange<Byte> {
|
||||
@Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive"))
|
||||
override val end: Byte get() = endInclusive
|
||||
|
||||
override val start: Byte get() = first
|
||||
override val endInclusive: Byte get() = last
|
||||
|
||||
override fun contains(value: Byte): Boolean = start <= value && value <= endInclusive
|
||||
|
||||
override fun isEmpty(): Boolean = start > endInclusive
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is ByteRange && (isEmpty() && other.isEmpty() ||
|
||||
start == other.start && endInclusive == other.endInclusive)
|
||||
|
||||
override fun hashCode(): Int =
|
||||
if (isEmpty()) -1 else (31 * start.toInt() + endInclusive.toInt())
|
||||
|
||||
override fun toString(): String = "$start..$endInclusive"
|
||||
|
||||
companion object {
|
||||
/** An empty range of values of type Byte. */
|
||||
public val EMPTY: ByteRange = ByteRange(1, 0)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A range of values of type `Char`.
|
||||
*/
|
||||
@@ -77,36 +47,6 @@ public class CharRange(start: Char, endInclusive: Char) : CharProgression(start,
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Use IntRange instead.", ReplaceWith("IntRange"), level = DeprecationLevel.WARNING)
|
||||
/**
|
||||
* A range of values of type `Short`.
|
||||
*/
|
||||
public class ShortRange(start: Short, endInclusive: Short) : ShortProgression(start, endInclusive, 1), ClosedRange<Short> {
|
||||
@Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive"))
|
||||
override val end: Short get() = endInclusive
|
||||
|
||||
override val start: Short get() = first
|
||||
override val endInclusive: Short get() = last
|
||||
|
||||
override fun contains(value: Short): Boolean = start <= value && value <= endInclusive
|
||||
|
||||
override fun isEmpty(): Boolean = start > endInclusive
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is ShortRange && (isEmpty() && other.isEmpty() ||
|
||||
start == other.start && endInclusive == other.endInclusive)
|
||||
|
||||
override fun hashCode(): Int =
|
||||
if (isEmpty()) -1 else (31 * start.toInt() + endInclusive.toInt())
|
||||
|
||||
override fun toString(): String = "$start..$endInclusive"
|
||||
|
||||
companion object {
|
||||
/** An empty range of values of type Short. */
|
||||
public val EMPTY: ShortRange = ShortRange(1, 0)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A range of values of type `Int`.
|
||||
*/
|
||||
|
||||
@@ -411,10 +411,9 @@ public abstract class KotlinBuiltIns {
|
||||
@NotNull
|
||||
public Set<DeclarationDescriptor> getIntegralRanges() {
|
||||
return SetsKt.<DeclarationDescriptor>setOf(
|
||||
getBuiltInClassByName("ByteRange", rangesPackageFragment),
|
||||
getBuiltInClassByName("ShortRange", rangesPackageFragment),
|
||||
getBuiltInClassByName("CharRange", rangesPackageFragment),
|
||||
getBuiltInClassByName("IntRange", rangesPackageFragment)
|
||||
// TODO: contains in LongRange should be optimized too
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user