Drop Progression<T> and its deprecated properties: start, end, increment.
Drop deprecated range extensions. Make progression constructors private.
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kotlin
|
||||
|
||||
/**
|
||||
* Represents a sequence of numbers or characters with a given start value, end value and step.
|
||||
* This class is intended to be used in 'for' loops, and the JVM backend suggests efficient
|
||||
* bytecode generation for it. Progressions with a step of -1 can be created through the
|
||||
* `downTo` method on classes representing primitive types.
|
||||
*/
|
||||
@Deprecated("This generic progression interface is not of much use and will be removed soon. Use concrete progression implementation instead: IntProgression, LongProgression or CharProgression.")
|
||||
public interface Progression<out N : Any> : Iterable<N> {
|
||||
/**
|
||||
* The start value of the progression.
|
||||
*/
|
||||
public val start: N
|
||||
|
||||
/**
|
||||
* The end value of the progression (inclusive).
|
||||
*/
|
||||
public val end: N
|
||||
|
||||
/**
|
||||
* The step of the progression.
|
||||
*/
|
||||
public val increment: Number
|
||||
}
|
||||
@@ -24,13 +24,12 @@ import kotlin.internal.getProgressionLastElement
|
||||
* A progression of values of type `Char`.
|
||||
*/
|
||||
public open class CharProgression
|
||||
@Deprecated("This constructor will become private soon. Use CharProgression.fromClosedRange() instead.", ReplaceWith("CharProgression.fromClosedRange(start, endInclusive, step)"))
|
||||
public constructor
|
||||
internal constructor
|
||||
(
|
||||
start: Char,
|
||||
endInclusive: Char,
|
||||
step: Int
|
||||
) : Progression<Char> /*, Iterable<Char> */ {
|
||||
) : Iterable<Char> {
|
||||
init {
|
||||
if (step == 0) throw IllegalArgumentException("Step must be non-zero")
|
||||
}
|
||||
@@ -50,19 +49,6 @@ public open class CharProgression
|
||||
*/
|
||||
public val step: Int = step
|
||||
|
||||
@Deprecated("Use 'first' property instead.", ReplaceWith("first"))
|
||||
public override val start: Char get() = first
|
||||
|
||||
/**
|
||||
* The end value of the progression (inclusive).
|
||||
*/
|
||||
@Deprecated("Use 'last' property instead.")
|
||||
public override val end: Char = endInclusive
|
||||
|
||||
@Deprecated("Use 'step' property instead.", ReplaceWith("step"))
|
||||
public override val increment: Int get() = step
|
||||
|
||||
|
||||
override fun iterator(): CharIterator = CharProgressionIterator(first, last, step)
|
||||
|
||||
/** Checks if the progression is empty. */
|
||||
@@ -92,13 +78,12 @@ public open class CharProgression
|
||||
* A progression of values of type `Int`.
|
||||
*/
|
||||
public open class IntProgression
|
||||
@Deprecated("This constructor will become private soon. Use IntProgression.fromClosedRange() instead.", ReplaceWith("IntProgression.fromClosedRange(start, endInclusive, step)"))
|
||||
public constructor
|
||||
internal constructor
|
||||
(
|
||||
start: Int,
|
||||
endInclusive: Int,
|
||||
step: Int
|
||||
) : Progression<Int> /*, Iterable<Int> */ {
|
||||
) : Iterable<Int> {
|
||||
init {
|
||||
if (step == 0) throw IllegalArgumentException("Step must be non-zero")
|
||||
}
|
||||
@@ -118,19 +103,6 @@ public open class IntProgression
|
||||
*/
|
||||
public val step: Int = step
|
||||
|
||||
@Deprecated("Use 'first' property instead.", ReplaceWith("first"))
|
||||
public override val start: Int get() = first
|
||||
|
||||
/**
|
||||
* The end value of the progression (inclusive).
|
||||
*/
|
||||
@Deprecated("Use 'last' property instead.")
|
||||
public override val end: Int = endInclusive
|
||||
|
||||
@Deprecated("Use 'step' property instead.", ReplaceWith("step"))
|
||||
public override val increment: Int get() = step
|
||||
|
||||
|
||||
override fun iterator(): IntIterator = IntProgressionIterator(first, last, step)
|
||||
|
||||
/** Checks if the progression is empty. */
|
||||
@@ -160,13 +132,12 @@ public open class IntProgression
|
||||
* A progression of values of type `Long`.
|
||||
*/
|
||||
public open class LongProgression
|
||||
@Deprecated("This constructor will become private soon. Use LongProgression.fromClosedRange() instead.", ReplaceWith("LongProgression.fromClosedRange(start, endInclusive, step)"))
|
||||
public constructor
|
||||
internal constructor
|
||||
(
|
||||
start: Long,
|
||||
endInclusive: Long,
|
||||
step: Long
|
||||
) : Progression<Long> /*, Iterable<Long> */ {
|
||||
) : Iterable<Long> {
|
||||
init {
|
||||
if (step == 0L) throw IllegalArgumentException("Step must be non-zero")
|
||||
}
|
||||
@@ -186,19 +157,6 @@ public open class LongProgression
|
||||
*/
|
||||
public val step: Long = step
|
||||
|
||||
@Deprecated("Use 'first' property instead.", ReplaceWith("first"))
|
||||
public override val start: Long get() = first
|
||||
|
||||
/**
|
||||
* The end value of the progression (inclusive).
|
||||
*/
|
||||
@Deprecated("Use 'last' property instead.")
|
||||
public override val end: Long = endInclusive
|
||||
|
||||
@Deprecated("Use 'step' property instead.", ReplaceWith("step"))
|
||||
public override val increment: Long get() = step
|
||||
|
||||
|
||||
override fun iterator(): LongIterator = LongProgressionIterator(first, last, step)
|
||||
|
||||
/** Checks if the progression is empty. */
|
||||
|
||||
@@ -22,24 +22,21 @@ package kotlin.ranges
|
||||
* A range of values of type `Char`.
|
||||
*/
|
||||
public class CharRange(start: Char, endInclusive: Char) : CharProgression(start, endInclusive, 1), ClosedRange<Char> {
|
||||
@Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive"))
|
||||
override val end: Char get() = endInclusive
|
||||
|
||||
override val start: Char get() = first
|
||||
override val endInclusive: Char get() = last
|
||||
|
||||
override fun contains(value: Char): Boolean = start <= value && value <= endInclusive
|
||||
override fun contains(value: Char): Boolean = first <= value && value <= last
|
||||
|
||||
override fun isEmpty(): Boolean = start > endInclusive
|
||||
override fun isEmpty(): Boolean = first > last
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is CharRange && (isEmpty() && other.isEmpty() ||
|
||||
start == other.start && endInclusive == other.endInclusive)
|
||||
first == other.first && last == other.last)
|
||||
|
||||
override fun hashCode(): Int =
|
||||
if (isEmpty()) -1 else (31 * start.toInt() + endInclusive.toInt())
|
||||
if (isEmpty()) -1 else (31 * first.toInt() + last.toInt())
|
||||
|
||||
override fun toString(): String = "$start..$endInclusive"
|
||||
override fun toString(): String = "$first..$last"
|
||||
|
||||
companion object {
|
||||
/** An empty range of values of type Char. */
|
||||
@@ -51,24 +48,21 @@ public class CharRange(start: Char, endInclusive: Char) : CharProgression(start,
|
||||
* A range of values of type `Int`.
|
||||
*/
|
||||
public class IntRange(start: Int, endInclusive: Int) : IntProgression(start, endInclusive, 1), ClosedRange<Int> {
|
||||
@Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive"))
|
||||
override val end: Int get() = endInclusive
|
||||
|
||||
override val start: Int get() = first
|
||||
override val endInclusive: Int get() = last
|
||||
|
||||
override fun contains(value: Int): Boolean = start <= value && value <= endInclusive
|
||||
override fun contains(value: Int): Boolean = first <= value && value <= last
|
||||
|
||||
override fun isEmpty(): Boolean = start > endInclusive
|
||||
override fun isEmpty(): Boolean = first > last
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is IntRange && (isEmpty() && other.isEmpty() ||
|
||||
start == other.start && endInclusive == other.endInclusive)
|
||||
first == other.first && last == other.last)
|
||||
|
||||
override fun hashCode(): Int =
|
||||
if (isEmpty()) -1 else (31 * start + endInclusive)
|
||||
if (isEmpty()) -1 else (31 * first + last)
|
||||
|
||||
override fun toString(): String = "$start..$endInclusive"
|
||||
override fun toString(): String = "$first..$last"
|
||||
|
||||
companion object {
|
||||
/** An empty range of values of type Int. */
|
||||
@@ -80,24 +74,21 @@ public class IntRange(start: Int, endInclusive: Int) : IntProgression(start, end
|
||||
* A range of values of type `Long`.
|
||||
*/
|
||||
public class LongRange(start: Long, endInclusive: Long) : LongProgression(start, endInclusive, 1), ClosedRange<Long> {
|
||||
@Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive"))
|
||||
override val end: Long get() = endInclusive
|
||||
|
||||
override val start: Long get() = first
|
||||
override val endInclusive: Long get() = last
|
||||
|
||||
override fun contains(value: Long): Boolean = start <= value && value <= endInclusive
|
||||
override fun contains(value: Long): Boolean = first <= value && value <= last
|
||||
|
||||
override fun isEmpty(): Boolean = start > endInclusive
|
||||
override fun isEmpty(): Boolean = first > last
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is LongRange && (isEmpty() && other.isEmpty() ||
|
||||
start == other.start && endInclusive == other.endInclusive)
|
||||
first == other.first && last == other.last)
|
||||
|
||||
override fun hashCode(): Int =
|
||||
if (isEmpty()) -1 else (31 * (start xor (start ushr 32)) + (endInclusive xor (endInclusive ushr 32))).toInt()
|
||||
if (isEmpty()) -1 else (31 * (first xor (first ushr 32)) + (last xor (last ushr 32))).toInt()
|
||||
|
||||
override fun toString(): String = "$start..$endInclusive"
|
||||
override fun toString(): String = "$first..$last"
|
||||
|
||||
companion object {
|
||||
/** An empty range of values of type Long. */
|
||||
|
||||
Reference in New Issue
Block a user