Hide deprecated Double/FloatArray.contains/indexOf/lastIndexOf

This commit is contained in:
Ilya Gorbunov
2022-04-08 14:08:14 +03:00
committed by Space
parent b35c571a23
commit 1845e326d1
6 changed files with 41 additions and 43 deletions
@@ -1044,11 +1044,11 @@ public operator fun kotlin.ByteArray.contains(element: kotlin.Byte): kotlin.Bool
public operator fun kotlin.CharArray.contains(element: kotlin.Char): kotlin.Boolean
@kotlin.Deprecated(message = "The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'any { it == element }' instead to continue using this behavior, or '.asList().contains(element: T)' to get the same search behavior as in a list.", replaceWith = kotlin.ReplaceWith(expression = "any { it == element }", imports = {}))
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", warningSince = "1.4")
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", hiddenSince = "1.7", warningSince = "1.4")
public operator fun kotlin.DoubleArray.contains(element: kotlin.Double): kotlin.Boolean
@kotlin.Deprecated(message = "The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'any { it == element }' instead to continue using this behavior, or '.asList().contains(element: T)' to get the same search behavior as in a list.", replaceWith = kotlin.ReplaceWith(expression = "any { it == element }", imports = {}))
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", warningSince = "1.4")
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", hiddenSince = "1.7", warningSince = "1.4")
public operator fun kotlin.FloatArray.contains(element: kotlin.Float): kotlin.Boolean
public operator fun kotlin.IntArray.contains(element: kotlin.Int): kotlin.Boolean
@@ -3513,11 +3513,11 @@ public fun kotlin.ByteArray.indexOf(element: kotlin.Byte): kotlin.Int
public fun kotlin.CharArray.indexOf(element: kotlin.Char): kotlin.Int
@kotlin.Deprecated(message = "The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'indexOfFirst { it == element }' instead to continue using this behavior, or '.asList().indexOf(element: T)' to get the same search behavior as in a list.", replaceWith = kotlin.ReplaceWith(expression = "indexOfFirst { it == element }", imports = {}))
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", warningSince = "1.4")
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", hiddenSince = "1.7", warningSince = "1.4")
public fun kotlin.DoubleArray.indexOf(element: kotlin.Double): kotlin.Int
@kotlin.Deprecated(message = "The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'indexOfFirst { it == element }' instead to continue using this behavior, or '.asList().indexOf(element: T)' to get the same search behavior as in a list.", replaceWith = kotlin.ReplaceWith(expression = "indexOfFirst { it == element }", imports = {}))
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", warningSince = "1.4")
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", hiddenSince = "1.7", warningSince = "1.4")
public fun kotlin.FloatArray.indexOf(element: kotlin.Float): kotlin.Int
public fun kotlin.IntArray.indexOf(element: kotlin.Int): kotlin.Int
@@ -3872,11 +3872,11 @@ public fun kotlin.ByteArray.lastIndexOf(element: kotlin.Byte): kotlin.Int
public fun kotlin.CharArray.lastIndexOf(element: kotlin.Char): kotlin.Int
@kotlin.Deprecated(message = "The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'indexOfLast { it == element }' instead to continue using this behavior, or '.asList().lastIndexOf(element: T)' to get the same search behavior as in a list.", replaceWith = kotlin.ReplaceWith(expression = "indexOfLast { it == element }", imports = {}))
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", warningSince = "1.4")
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", hiddenSince = "1.7", warningSince = "1.4")
public fun kotlin.DoubleArray.lastIndexOf(element: kotlin.Double): kotlin.Int
@kotlin.Deprecated(message = "The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'indexOfLast { it == element }' instead to continue using this behavior, or '.asList().lastIndexOf(element: T)' to get the same search behavior as in a list.", replaceWith = kotlin.ReplaceWith(expression = "indexOfLast { it == element }", imports = {}))
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", warningSince = "1.4")
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", hiddenSince = "1.7", warningSince = "1.4")
public fun kotlin.FloatArray.lastIndexOf(element: kotlin.Float): kotlin.Int
public fun kotlin.IntArray.lastIndexOf(element: kotlin.Int): kotlin.Int
@@ -1044,11 +1044,11 @@ public operator fun kotlin.ByteArray.contains(element: kotlin.Byte): kotlin.Bool
public operator fun kotlin.CharArray.contains(element: kotlin.Char): kotlin.Boolean
@kotlin.Deprecated(message = "The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'any { it == element }' instead to continue using this behavior, or '.asList().contains(element: T)' to get the same search behavior as in a list.", replaceWith = kotlin.ReplaceWith(expression = "any { it == element }", imports = {}))
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", warningSince = "1.4")
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", hiddenSince = "1.7", warningSince = "1.4")
public operator fun kotlin.DoubleArray.contains(element: kotlin.Double): kotlin.Boolean
@kotlin.Deprecated(message = "The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'any { it == element }' instead to continue using this behavior, or '.asList().contains(element: T)' to get the same search behavior as in a list.", replaceWith = kotlin.ReplaceWith(expression = "any { it == element }", imports = {}))
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", warningSince = "1.4")
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", hiddenSince = "1.7", warningSince = "1.4")
public operator fun kotlin.FloatArray.contains(element: kotlin.Float): kotlin.Boolean
public operator fun kotlin.IntArray.contains(element: kotlin.Int): kotlin.Boolean
@@ -3483,11 +3483,11 @@ public fun kotlin.ByteArray.indexOf(element: kotlin.Byte): kotlin.Int
public fun kotlin.CharArray.indexOf(element: kotlin.Char): kotlin.Int
@kotlin.Deprecated(message = "The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'indexOfFirst { it == element }' instead to continue using this behavior, or '.asList().indexOf(element: T)' to get the same search behavior as in a list.", replaceWith = kotlin.ReplaceWith(expression = "indexOfFirst { it == element }", imports = {}))
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", warningSince = "1.4")
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", hiddenSince = "1.7", warningSince = "1.4")
public fun kotlin.DoubleArray.indexOf(element: kotlin.Double): kotlin.Int
@kotlin.Deprecated(message = "The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'indexOfFirst { it == element }' instead to continue using this behavior, or '.asList().indexOf(element: T)' to get the same search behavior as in a list.", replaceWith = kotlin.ReplaceWith(expression = "indexOfFirst { it == element }", imports = {}))
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", warningSince = "1.4")
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", hiddenSince = "1.7", warningSince = "1.4")
public fun kotlin.FloatArray.indexOf(element: kotlin.Float): kotlin.Int
public fun kotlin.IntArray.indexOf(element: kotlin.Int): kotlin.Int
@@ -3842,11 +3842,11 @@ public fun kotlin.ByteArray.lastIndexOf(element: kotlin.Byte): kotlin.Int
public fun kotlin.CharArray.lastIndexOf(element: kotlin.Char): kotlin.Int
@kotlin.Deprecated(message = "The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'indexOfLast { it == element }' instead to continue using this behavior, or '.asList().lastIndexOf(element: T)' to get the same search behavior as in a list.", replaceWith = kotlin.ReplaceWith(expression = "indexOfLast { it == element }", imports = {}))
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", warningSince = "1.4")
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", hiddenSince = "1.7", warningSince = "1.4")
public fun kotlin.DoubleArray.lastIndexOf(element: kotlin.Double): kotlin.Int
@kotlin.Deprecated(message = "The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'indexOfLast { it == element }' instead to continue using this behavior, or '.asList().lastIndexOf(element: T)' to get the same search behavior as in a list.", replaceWith = kotlin.ReplaceWith(expression = "indexOfLast { it == element }", imports = {}))
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", warningSince = "1.4")
@kotlin.DeprecatedSinceKotlin(errorSince = "1.6", hiddenSince = "1.7", warningSince = "1.4")
public fun kotlin.FloatArray.lastIndexOf(element: kotlin.Float): kotlin.Int
public fun kotlin.IntArray.lastIndexOf(element: kotlin.Int): kotlin.Int
@@ -551,20 +551,18 @@ public operator fun LongArray.contains(element: Long): Boolean {
* Returns `true` if [element] is found in the array.
*/
@Deprecated("The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'any { it == element }' instead to continue using this behavior, or '.asList().contains(element: T)' to get the same search behavior as in a list.", ReplaceWith("any { it == element }"))
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.6")
@Suppress("DEPRECATION_ERROR")
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.6", hiddenSince = "1.7")
public operator fun FloatArray.contains(element: Float): Boolean {
return indexOf(element) >= 0
return any { it == element }
}
/**
* Returns `true` if [element] is found in the array.
*/
@Deprecated("The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'any { it == element }' instead to continue using this behavior, or '.asList().contains(element: T)' to get the same search behavior as in a list.", ReplaceWith("any { it == element }"))
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.6")
@Suppress("DEPRECATION_ERROR")
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.6", hiddenSince = "1.7")
public operator fun DoubleArray.contains(element: Double): Boolean {
return indexOf(element) >= 0
return any { it == element }
}
/**
@@ -1574,7 +1572,7 @@ public fun LongArray.indexOf(element: Long): Int {
* Returns first index of [element], or -1 if the array does not contain element.
*/
@Deprecated("The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'indexOfFirst { it == element }' instead to continue using this behavior, or '.asList().indexOf(element: T)' to get the same search behavior as in a list.", ReplaceWith("indexOfFirst { it == element }"))
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.6")
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.6", hiddenSince = "1.7")
public fun FloatArray.indexOf(element: Float): Int {
for (index in indices) {
if (element == this[index]) {
@@ -1588,7 +1586,7 @@ public fun FloatArray.indexOf(element: Float): Int {
* Returns first index of [element], or -1 if the array does not contain element.
*/
@Deprecated("The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'indexOfFirst { it == element }' instead to continue using this behavior, or '.asList().indexOf(element: T)' to get the same search behavior as in a list.", ReplaceWith("indexOfFirst { it == element }"))
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.6")
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.6", hiddenSince = "1.7")
public fun DoubleArray.indexOf(element: Double): Int {
for (index in indices) {
if (element == this[index]) {
@@ -2162,7 +2160,7 @@ public fun LongArray.lastIndexOf(element: Long): Int {
* Returns last index of [element], or -1 if the array does not contain element.
*/
@Deprecated("The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'indexOfLast { it == element }' instead to continue using this behavior, or '.asList().lastIndexOf(element: T)' to get the same search behavior as in a list.", ReplaceWith("indexOfLast { it == element }"))
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.6")
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.6", hiddenSince = "1.7")
public fun FloatArray.lastIndexOf(element: Float): Int {
for (index in indices.reversed()) {
if (element == this[index]) {
@@ -2176,7 +2174,7 @@ public fun FloatArray.lastIndexOf(element: Float): Int {
* Returns last index of [element], or -1 if the array does not contain element.
*/
@Deprecated("The function has unclear behavior when searching for NaN or zero values and will be removed soon. Use 'indexOfLast { it == element }' instead to continue using this behavior, or '.asList().lastIndexOf(element: T)' to get the same search behavior as in a list.", ReplaceWith("indexOfLast { it == element }"))
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.6")
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.6", hiddenSince = "1.7")
public fun DoubleArray.lastIndexOf(element: Double): Int {
for (index in indices.reversed()) {
if (element == this[index]) {
@@ -502,7 +502,6 @@ class ArraysTest {
// for each arr with size > 0 arr.average() = arr.sum().toDouble() / arr.size()
}
@Suppress("DEPRECATION_ERROR")
@Test fun indexOfInPrimitiveArrays() {
expect(-1) { byteArrayOf(1, 2, 3).indexOf(0) }
expect(0) { byteArrayOf(1, 2, 3).indexOf(1) }
@@ -524,15 +523,15 @@ class ArraysTest {
expect(1) { longArrayOf(1, 2, 3).indexOf(2) }
expect(2) { longArrayOf(1, 2, 3).indexOf(3) }
expect(-1) { floatArrayOf(1.0f, 2.0f, 3.0f).indexOf(0f) }
expect(0) { floatArrayOf(1.0f, 2.0f, 3.0f).indexOf(1.0f) }
expect(1) { floatArrayOf(1.0f, 2.0f, 3.0f).indexOf(2.0f) }
expect(2) { floatArrayOf(1.0f, 2.0f, 3.0f).indexOf(3.0f) }
expect(-1) { doubleArrayOf(1.0, 2.0, 3.0).indexOf(0.0) }
expect(0) { doubleArrayOf(1.0, 2.0, 3.0).indexOf(1.0) }
expect(1) { doubleArrayOf(1.0, 2.0, 3.0).indexOf(2.0) }
expect(2) { doubleArrayOf(1.0, 2.0, 3.0).indexOf(3.0) }
// expect(-1) { floatArrayOf(1.0f, 2.0f, 3.0f).indexOf(0f) }
// expect(0) { floatArrayOf(1.0f, 2.0f, 3.0f).indexOf(1.0f) }
// expect(1) { floatArrayOf(1.0f, 2.0f, 3.0f).indexOf(2.0f) }
// expect(2) { floatArrayOf(1.0f, 2.0f, 3.0f).indexOf(3.0f) }
//
// expect(-1) { doubleArrayOf(1.0, 2.0, 3.0).indexOf(0.0) }
// expect(0) { doubleArrayOf(1.0, 2.0, 3.0).indexOf(1.0) }
// expect(1) { doubleArrayOf(1.0, 2.0, 3.0).indexOf(2.0) }
// expect(2) { doubleArrayOf(1.0, 2.0, 3.0).indexOf(3.0) }
expect(-1) { charArrayOf('a', 'b', 'c').indexOf('z') }
expect(0) { charArrayOf('a', 'b', 'c').indexOf('a') }
@@ -870,8 +870,8 @@ public final class kotlin/collections/ArraysKt {
public static synthetic fun binarySearch$default ([SSIIILjava/lang/Object;)I
public static final fun contains ([BB)Z
public static final fun contains ([CC)Z
public static final fun contains ([DD)Z
public static final fun contains ([FF)Z
public static final synthetic fun contains ([DD)Z
public static final synthetic fun contains ([FF)Z
public static final fun contains ([II)Z
public static final fun contains ([JJ)Z
public static final fun contains ([Ljava/lang/Object;Ljava/lang/Object;)Z
@@ -1223,8 +1223,8 @@ public final class kotlin/collections/ArraysKt {
public static final fun groupingBy ([Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Lkotlin/collections/Grouping;
public static final fun indexOf ([BB)I
public static final fun indexOf ([CC)I
public static final fun indexOf ([DD)I
public static final fun indexOf ([FF)I
public static final synthetic fun indexOf ([DD)I
public static final synthetic fun indexOf ([FF)I
public static final fun indexOf ([II)I
public static final fun indexOf ([JJ)I
public static final fun indexOf ([Ljava/lang/Object;Ljava/lang/Object;)I
@@ -1313,8 +1313,8 @@ public final class kotlin/collections/ArraysKt {
public static final fun last ([ZLkotlin/jvm/functions/Function1;)Z
public static final fun lastIndexOf ([BB)I
public static final fun lastIndexOf ([CC)I
public static final fun lastIndexOf ([DD)I
public static final fun lastIndexOf ([FF)I
public static final synthetic fun lastIndexOf ([DD)I
public static final synthetic fun lastIndexOf ([FF)I
public static final fun lastIndexOf ([II)I
public static final fun lastIndexOf ([JJ)I
public static final fun lastIndexOf ([Ljava/lang/Object;Ljava/lang/Object;)I
@@ -45,11 +45,11 @@ object Elements : TemplateGroupBase() {
doc { "Returns `true` if [element] is found in the ${f.collection}." }
typeParam("@kotlin.internal.OnlyInputTypes T")
if (f == ArraysOfPrimitives && primitive!!.isFloatingPoint()) {
val isDeprecated = f == ArraysOfPrimitives && primitive!!.isFloatingPoint()
if (isDeprecated) {
val replacement = "any { it == element }"
val message = floatingSearchDeprecationMessage(signature, replacement)
deprecate(Deprecation(message, replacement, warningSince = "1.4", errorSince = "1.6"))
annotation("""@Suppress("DEPRECATION_ERROR")""")
deprecate(Deprecation(message, replacement, warningSince = "1.4", errorSince = "1.6", hiddenSince = "1.7"))
}
returns("Boolean")
body(Iterables) {
@@ -59,6 +59,7 @@ object Elements : TemplateGroupBase() {
return indexOf(element) >= 0
"""
}
if (!isDeprecated)
body(ArraysOfPrimitives, ArraysOfObjects, Sequences) {
"""
return indexOf(element) >= 0
@@ -77,7 +78,7 @@ object Elements : TemplateGroupBase() {
if (f == ArraysOfPrimitives && primitive!!.isFloatingPoint()) {
val replacement = "indexOfFirst { it == element }"
val message = floatingSearchDeprecationMessage(signature, replacement)
deprecate(Deprecation(message, replacement, warningSince = "1.4", errorSince = "1.6"))
deprecate(Deprecation(message, replacement, warningSince = "1.4", errorSince = "1.6", hiddenSince = "1.7"))
}
returns("Int")
body {
@@ -142,7 +143,7 @@ object Elements : TemplateGroupBase() {
if (f == ArraysOfPrimitives && primitive!!.isFloatingPoint()) {
val replacement = "indexOfLast { it == element }"
val message = floatingSearchDeprecationMessage(signature, replacement)
deprecate(Deprecation(message, replacement, warningSince = "1.4", errorSince = "1.6"))
deprecate(Deprecation(message, replacement, warningSince = "1.4", errorSince = "1.6", hiddenSince = "1.7"))
}
returns("Int")
body {