Drop Range<T> interface and its extensions.
This commit is contained in:
@@ -20,45 +20,12 @@ package kotlin.ranges
|
|||||||
* Represents a range of values (for example, numbers or characters).
|
* Represents a range of values (for example, numbers or characters).
|
||||||
* See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/ranges.html) for more information.
|
* See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/ranges.html) for more information.
|
||||||
*/
|
*/
|
||||||
@Deprecated("This range has unclear inclusiveness of end value. Use ClosedRange instead.", ReplaceWith("ClosedRange<T>"))
|
public interface ClosedRange<T: Comparable<T>> {
|
||||||
public interface Range<T : Comparable<T>> {
|
|
||||||
/**
|
/**
|
||||||
* The minimum value in the range.
|
* The minimum value in the range.
|
||||||
*/
|
*/
|
||||||
public val start: T
|
public val start: T
|
||||||
|
|
||||||
/**
|
|
||||||
* The maximum value in the range (inclusive).
|
|
||||||
*/
|
|
||||||
public val end: T
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to the range.
|
|
||||||
*/
|
|
||||||
public operator fun contains(value: T): Boolean
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the range is empty.
|
|
||||||
*/
|
|
||||||
public fun isEmpty(): Boolean = start > end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a range of values (for example, numbers or characters).
|
|
||||||
* See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/ranges.html) for more information.
|
|
||||||
*/
|
|
||||||
public interface ClosedRange<T: Comparable<T>> : Range<T> {
|
|
||||||
/**
|
|
||||||
* The minimum value in the range.
|
|
||||||
*/
|
|
||||||
public override val start: T
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The maximum value in the range (inclusive).
|
|
||||||
*/
|
|
||||||
@Deprecated("Use endInclusive instead.", ReplaceWith("endInclusive"))
|
|
||||||
public override val end: T get() = endInclusive
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum value in the range (inclusive).
|
* The maximum value in the range (inclusive).
|
||||||
*/
|
*/
|
||||||
@@ -67,10 +34,10 @@ public interface ClosedRange<T: Comparable<T>> : Range<T> {
|
|||||||
/**
|
/**
|
||||||
* Checks whether the specified [value] belongs to the range.
|
* Checks whether the specified [value] belongs to the range.
|
||||||
*/
|
*/
|
||||||
public override operator fun contains(value: T): Boolean = value >= start && value <= endInclusive
|
public operator fun contains(value: T): Boolean = value >= start && value <= endInclusive
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the range is empty.
|
* Checks whether the range is empty.
|
||||||
*/
|
*/
|
||||||
public override fun isEmpty(): Boolean = start > endInclusive
|
public fun isEmpty(): Boolean = start > endInclusive
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,15 +67,6 @@ public fun Short.`-until`(to: Short): ShortRange {
|
|||||||
return ShortRange(this, to_)
|
return ShortRange(this, to_)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("intRangeContains")
|
|
||||||
public operator fun Range<Int>.contains(value: Byte): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -84,15 +75,6 @@ public operator fun ClosedRange<Int>.contains(value: Byte): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("longRangeContains")
|
|
||||||
public operator fun Range<Long>.contains(value: Byte): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -101,15 +83,6 @@ public operator fun ClosedRange<Long>.contains(value: Byte): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("shortRangeContains")
|
|
||||||
public operator fun Range<Short>.contains(value: Byte): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -118,15 +91,6 @@ public operator fun ClosedRange<Short>.contains(value: Byte): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("doubleRangeContains")
|
|
||||||
public operator fun Range<Double>.contains(value: Byte): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -135,15 +99,6 @@ public operator fun ClosedRange<Double>.contains(value: Byte): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("floatRangeContains")
|
|
||||||
public operator fun Range<Float>.contains(value: Byte): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -152,15 +107,6 @@ public operator fun ClosedRange<Float>.contains(value: Byte): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("intRangeContains")
|
|
||||||
public operator fun Range<Int>.contains(value: Double): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -169,15 +115,6 @@ public operator fun ClosedRange<Int>.contains(value: Double): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("longRangeContains")
|
|
||||||
public operator fun Range<Long>.contains(value: Double): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -186,15 +123,6 @@ public operator fun ClosedRange<Long>.contains(value: Double): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("byteRangeContains")
|
|
||||||
public operator fun Range<Byte>.contains(value: Double): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -203,15 +131,6 @@ public operator fun ClosedRange<Byte>.contains(value: Double): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("shortRangeContains")
|
|
||||||
public operator fun Range<Short>.contains(value: Double): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -220,15 +139,6 @@ public operator fun ClosedRange<Short>.contains(value: Double): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("floatRangeContains")
|
|
||||||
public operator fun Range<Float>.contains(value: Double): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -237,15 +147,6 @@ public operator fun ClosedRange<Float>.contains(value: Double): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("intRangeContains")
|
|
||||||
public operator fun Range<Int>.contains(value: Float): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -254,15 +155,6 @@ public operator fun ClosedRange<Int>.contains(value: Float): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("longRangeContains")
|
|
||||||
public operator fun Range<Long>.contains(value: Float): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -271,15 +163,6 @@ public operator fun ClosedRange<Long>.contains(value: Float): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("byteRangeContains")
|
|
||||||
public operator fun Range<Byte>.contains(value: Float): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -288,15 +171,6 @@ public operator fun ClosedRange<Byte>.contains(value: Float): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("shortRangeContains")
|
|
||||||
public operator fun Range<Short>.contains(value: Float): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -305,15 +179,6 @@ public operator fun ClosedRange<Short>.contains(value: Float): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("doubleRangeContains")
|
|
||||||
public operator fun Range<Double>.contains(value: Float): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -322,15 +187,6 @@ public operator fun ClosedRange<Double>.contains(value: Float): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("longRangeContains")
|
|
||||||
public operator fun Range<Long>.contains(value: Int): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -339,15 +195,6 @@ public operator fun ClosedRange<Long>.contains(value: Int): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("byteRangeContains")
|
|
||||||
public operator fun Range<Byte>.contains(value: Int): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -356,15 +203,6 @@ public operator fun ClosedRange<Byte>.contains(value: Int): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("shortRangeContains")
|
|
||||||
public operator fun Range<Short>.contains(value: Int): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -373,15 +211,6 @@ public operator fun ClosedRange<Short>.contains(value: Int): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("doubleRangeContains")
|
|
||||||
public operator fun Range<Double>.contains(value: Int): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -390,15 +219,6 @@ public operator fun ClosedRange<Double>.contains(value: Int): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("floatRangeContains")
|
|
||||||
public operator fun Range<Float>.contains(value: Int): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -407,15 +227,6 @@ public operator fun ClosedRange<Float>.contains(value: Int): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("intRangeContains")
|
|
||||||
public operator fun Range<Int>.contains(value: Long): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -424,15 +235,6 @@ public operator fun ClosedRange<Int>.contains(value: Long): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("byteRangeContains")
|
|
||||||
public operator fun Range<Byte>.contains(value: Long): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -441,15 +243,6 @@ public operator fun ClosedRange<Byte>.contains(value: Long): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("shortRangeContains")
|
|
||||||
public operator fun Range<Short>.contains(value: Long): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -458,15 +251,6 @@ public operator fun ClosedRange<Short>.contains(value: Long): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("doubleRangeContains")
|
|
||||||
public operator fun Range<Double>.contains(value: Long): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -475,15 +259,6 @@ public operator fun ClosedRange<Double>.contains(value: Long): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("floatRangeContains")
|
|
||||||
public operator fun Range<Float>.contains(value: Long): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -492,15 +267,6 @@ public operator fun ClosedRange<Float>.contains(value: Long): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("intRangeContains")
|
|
||||||
public operator fun Range<Int>.contains(value: Short): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -509,15 +275,6 @@ public operator fun ClosedRange<Int>.contains(value: Short): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("longRangeContains")
|
|
||||||
public operator fun Range<Long>.contains(value: Short): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -526,15 +283,6 @@ public operator fun ClosedRange<Long>.contains(value: Short): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("byteRangeContains")
|
|
||||||
public operator fun Range<Byte>.contains(value: Short): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -543,15 +291,6 @@ public operator fun ClosedRange<Byte>.contains(value: Short): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("doubleRangeContains")
|
|
||||||
public operator fun Range<Double>.contains(value: Short): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -560,15 +299,6 @@ public operator fun ClosedRange<Double>.contains(value: Short): Boolean {
|
|||||||
return start <= value && value <= endInclusive
|
return start <= value && value <= endInclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified [value] belongs to this range.
|
|
||||||
*/
|
|
||||||
@Deprecated("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
@kotlin.jvm.JvmName("floatRangeContains")
|
|
||||||
public operator fun Range<Float>.contains(value: Short): Boolean {
|
|
||||||
return start <= value && value <= end
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the specified [value] belongs to this range.
|
* Checks if the specified [value] belongs to this range.
|
||||||
*/
|
*/
|
||||||
@@ -1286,73 +1016,3 @@ public fun Long.coerceIn(range: ClosedRange<Long>): Long {
|
|||||||
return if (this < range.start) range.start else if (this > range.endInclusive) range.endInclusive else this
|
return if (this < range.start) range.start else if (this > range.endInclusive) range.endInclusive 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("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
||||||
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("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
public fun Byte.coerceIn(range: Range<Byte>): Byte {
|
|
||||||
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("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
public fun Int.coerceIn(range: Range<Int>): Int {
|
|
||||||
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("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
public fun Long.coerceIn(range: Range<Long>): Long {
|
|
||||||
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("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
public fun Short.coerceIn(range: Range<Short>): Short {
|
|
||||||
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("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
||||||
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("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -46,50 +46,6 @@ fun comparables(): List<GenericFunction> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
templates add f("coerceIn(range: Range<T>)") {
|
|
||||||
sourceFile(SourceFile.Ranges)
|
|
||||||
only(Generic, Primitives)
|
|
||||||
only(numericPrimitives.filter { it.isIntegral() })
|
|
||||||
typeParam("T: Comparable<T>")
|
|
||||||
returns("SELF")
|
|
||||||
deprecate("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
deprecate(Generic) { forBinaryCompatibility }
|
|
||||||
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>)") {
|
|
||||||
sourceFile(SourceFile.Ranges)
|
|
||||||
only(Primitives)
|
|
||||||
only(numericPrimitives.filterNot { it.isIntegral() })
|
|
||||||
returns("SELF")
|
|
||||||
deprecate { forBinaryCompatibility } // force use generic overload instead
|
|
||||||
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: ClosedRange<T>)") {
|
templates add f("coerceIn(range: ClosedRange<T>)") {
|
||||||
sourceFile(SourceFile.Ranges)
|
sourceFile(SourceFile.Ranges)
|
||||||
only(Primitives, Generic)
|
only(Primitives, Generic)
|
||||||
|
|||||||
@@ -238,27 +238,12 @@ fun ranges(): List<GenericFunction> {
|
|||||||
templates addAll integralPermutations.map { until(it.first, it.second) }
|
templates addAll integralPermutations.map { until(it.first, it.second) }
|
||||||
templates addAll listOf(PrimitiveType.Byte, PrimitiveType.Short).permutations().map { untilDeprecated(it.first, it.second) }
|
templates addAll listOf(PrimitiveType.Byte, PrimitiveType.Short).permutations().map { untilDeprecated(it.first, it.second) }
|
||||||
|
|
||||||
fun containsDeprecated(rangeType: PrimitiveType, itemType: PrimitiveType) = f("contains(value: $itemType)") {
|
|
||||||
operator(true)
|
|
||||||
|
|
||||||
deprecate("Range<T> is deprecated. Use ClosedRange<T> instead.")
|
|
||||||
|
|
||||||
check(rangeType.isNumeric() == itemType.isNumeric()) { "Required rangeType and itemType both to be numeric or both not, got: $rangeType, $itemType" }
|
|
||||||
only(Ranges)
|
|
||||||
onlyPrimitives(Ranges, rangeType)
|
|
||||||
platformName("${rangeType.name.decapitalize()}RangeContains")
|
|
||||||
returns("Boolean")
|
|
||||||
doc { "Checks if the specified [value] belongs to this range." }
|
|
||||||
body { "return start <= value && value <= end" }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun contains(rangeType: PrimitiveType, itemType: PrimitiveType) = f("contains(value: $itemType)") {
|
fun contains(rangeType: PrimitiveType, itemType: PrimitiveType) = f("contains(value: $itemType)") {
|
||||||
operator(true)
|
operator(true)
|
||||||
|
|
||||||
check(rangeType.isNumeric() == itemType.isNumeric()) { "Required rangeType and itemType both to be numeric or both not, got: $rangeType, $itemType" }
|
check(rangeType.isNumeric() == itemType.isNumeric()) { "Required rangeType and itemType both to be numeric or both not, got: $rangeType, $itemType" }
|
||||||
only(Ranges)
|
only(Ranges)
|
||||||
onlyPrimitives(Ranges, rangeType)
|
onlyPrimitives(Ranges, rangeType)
|
||||||
customReceiver("ClosedRange<T>")
|
|
||||||
platformName("${rangeType.name.decapitalize()}RangeContains")
|
platformName("${rangeType.name.decapitalize()}RangeContains")
|
||||||
returns("Boolean")
|
returns("Boolean")
|
||||||
doc { "Checks if the specified [value] belongs to this range." }
|
doc { "Checks if the specified [value] belongs to this range." }
|
||||||
@@ -266,8 +251,7 @@ fun ranges(): List<GenericFunction> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
templates addAll numericPermutations.filter { it.first != it.second }
|
templates addAll numericPermutations.filter { it.first != it.second }.map { contains(it.first, it.second) }
|
||||||
.flatMap { listOf(containsDeprecated(it.first, it.second), contains(it.first, it.second)) }
|
|
||||||
|
|
||||||
|
|
||||||
return templates
|
return templates
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
|
|||||||
ArraysOfObjects -> "Array<${isAsteriskOrT.replace("T", "out T")}>"
|
ArraysOfObjects -> "Array<${isAsteriskOrT.replace("T", "out T")}>"
|
||||||
Strings -> "String"
|
Strings -> "String"
|
||||||
CharSequences -> "CharSequence"
|
CharSequences -> "CharSequence"
|
||||||
Ranges -> "Range<$isAsteriskOrT>"
|
Ranges -> "ClosedRange<$isAsteriskOrT>"
|
||||||
ArraysOfPrimitives -> primitive?.let { it.name + "Array" } ?: throw IllegalArgumentException("Primitive array should specify primitive type")
|
ArraysOfPrimitives -> primitive?.let { it.name + "Array" } ?: throw IllegalArgumentException("Primitive array should specify primitive type")
|
||||||
RangesOfPrimitives -> primitive?.let { it.name + "Range" } ?: throw IllegalArgumentException("Primitive range should specify primitive type")
|
RangesOfPrimitives -> primitive?.let { it.name + "Range" } ?: throw IllegalArgumentException("Primitive range should specify primitive type")
|
||||||
ProgressionsOfPrimitives -> primitive?.let { it.name + "Progression" } ?: throw IllegalArgumentException("Primitive progression should specify primitive type")
|
ProgressionsOfPrimitives -> primitive?.let { it.name + "Progression" } ?: throw IllegalArgumentException("Primitive progression should specify primitive type")
|
||||||
|
|||||||
Reference in New Issue
Block a user