From 521e0b679d0961f705c5c43e3fa71d585c507d0b Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Mon, 27 Jul 2015 20:08:44 +0300 Subject: [PATCH] Rename sortedDescendingBy to sortedByDescending --- libraries/stdlib/src/generated/_Ordering.kt | 158 +++++++++--------- .../stdlib/test/collections/ArraysTest.kt | 4 +- .../stdlib/test/collections/CollectionTest.kt | 6 +- .../stdlib/test/collections/SequenceTest.kt | 4 +- .../src/templates/Ordering.kt | 6 +- 5 files changed, 89 insertions(+), 89 deletions(-) diff --git a/libraries/stdlib/src/generated/_Ordering.kt b/libraries/stdlib/src/generated/_Ordering.kt index f34d1726de3..50e3e14dba0 100644 --- a/libraries/stdlib/src/generated/_Ordering.kt +++ b/libraries/stdlib/src/generated/_Ordering.kt @@ -182,7 +182,7 @@ public fun > Iterable.sortDescending(): List { /** * Returns a sorted list of all elements, in descending order by results of specified [order] function. */ -deprecated("This method may change its behavior soon. Use sortedDescendingBy() instead.", ReplaceWith("sortedDescendingBy(order)")) +deprecated("This method may change its behavior soon. Use sortedByDescending() instead.", ReplaceWith("sortedByDescending(order)")) public inline fun > Array.sortDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R): List { val sortedList = toArrayList() val sortBy: Comparator = compareByDescending(order) @@ -193,7 +193,7 @@ public inline fun > Array.sortDescendingBy(inlineOpt /** * Returns a sorted list of all elements, in descending order by results of specified [order] function. */ -deprecated("This method may change its behavior soon. Use sortedDescendingBy() instead.", ReplaceWith("sortedDescendingBy(order)")) +deprecated("This method may change its behavior soon. Use sortedByDescending() instead.", ReplaceWith("sortedByDescending(order)")) public inline fun > Iterable.sortDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R): List { val sortedList = toArrayList() val sortBy: Comparator = compareByDescending(order) @@ -372,6 +372,83 @@ public inline fun > Sequence.sortedBy(inlineOptions(Inli return sortedWith(compareBy(order)) } +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > Array.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > BooleanArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Boolean) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > ByteArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Byte) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > CharArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Char) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > DoubleArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Double) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > FloatArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Float) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > IntArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Int) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > LongArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Long) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > ShortArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Short) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > Iterable.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): List { + return sortedWith(compareByDescending(order)) +} + +/** + * Returns a sequence that yields elements of this sequence sorted descending according to natural sort order of the value returned by specified [order] function. + */ +public inline fun > Sequence.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): Sequence { + return sortedWith(compareByDescending(order)) +} + /** * Returns a list of all elements sorted descending according to their natural sort order. */ @@ -442,83 +519,6 @@ public fun > Sequence.sortedDescending(): Sequence { return sortedWith(comparator { x, y -> y.compareTo(x) }) } -/** - * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. - */ -public inline fun > Array.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): List { - return sortedWith(compareByDescending(order)) -} - -/** - * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. - */ -public inline fun > BooleanArray.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Boolean) -> R?): List { - return sortedWith(compareByDescending(order)) -} - -/** - * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. - */ -public inline fun > ByteArray.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Byte) -> R?): List { - return sortedWith(compareByDescending(order)) -} - -/** - * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. - */ -public inline fun > CharArray.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Char) -> R?): List { - return sortedWith(compareByDescending(order)) -} - -/** - * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. - */ -public inline fun > DoubleArray.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Double) -> R?): List { - return sortedWith(compareByDescending(order)) -} - -/** - * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. - */ -public inline fun > FloatArray.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Float) -> R?): List { - return sortedWith(compareByDescending(order)) -} - -/** - * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. - */ -public inline fun > IntArray.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Int) -> R?): List { - return sortedWith(compareByDescending(order)) -} - -/** - * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. - */ -public inline fun > LongArray.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Long) -> R?): List { - return sortedWith(compareByDescending(order)) -} - -/** - * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. - */ -public inline fun > ShortArray.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Short) -> R?): List { - return sortedWith(compareByDescending(order)) -} - -/** - * Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function. - */ -public inline fun > Iterable.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): List { - return sortedWith(compareByDescending(order)) -} - -/** - * Returns a sequence that yields elements of this sequence sorted descending according to natural sort order of the value returned by specified [order] function. - */ -public inline fun > Sequence.sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): Sequence { - return sortedWith(compareByDescending(order)) -} - /** * Returns a list of all elements sorted according to the specified [comparator]. */ diff --git a/libraries/stdlib/test/collections/ArraysTest.kt b/libraries/stdlib/test/collections/ArraysTest.kt index 6e4380d8b04..e3d321b856f 100644 --- a/libraries/stdlib/test/collections/ArraysTest.kt +++ b/libraries/stdlib/test/collections/ArraysTest.kt @@ -828,8 +828,8 @@ class ArraysTest { fun String.nullIfEmpty() = if (isEmpty()) null else this arrayOf(null, "").let { expect(listOf(null, "")) { it.sortedBy { it.orEmpty()}} - expect(listOf("", null)) { it.sortedDescendingBy { it.orEmpty() }} - expect(listOf("", null)) { it.sortedDescendingBy { it?.nullIfEmpty() }} + expect(listOf("", null)) { it.sortedByDescending { it.orEmpty() }} + expect(listOf("", null)) { it.sortedByDescending { it?.nullIfEmpty() }} } } diff --git a/libraries/stdlib/test/collections/CollectionTest.kt b/libraries/stdlib/test/collections/CollectionTest.kt index 4ecaa860dd7..b33dd6f24eb 100644 --- a/libraries/stdlib/test/collections/CollectionTest.kt +++ b/libraries/stdlib/test/collections/CollectionTest.kt @@ -567,15 +567,15 @@ class CollectionTest { test fun sortedBy() { assertEquals(listOf("two" to 2, "three" to 3), listOf("three" to 3, "two" to 2).sortedBy { it.second }) assertEquals(listOf("three" to 3, "two" to 2), listOf("three" to 3, "two" to 2).sortedBy { it.first }) - assertEquals(listOf("three", "two"), listOf("two", "three").sortedDescendingBy { it.length() }) + assertEquals(listOf("three", "two"), listOf("two", "three").sortedByDescending { it.length() }) } test fun sortedNullableBy() { fun String.nullIfEmpty() = if (isEmpty()) null else this listOf(null, "").let { expect(listOf(null, "")) { it.sortedBy { it.orEmpty()}} - expect(listOf("", null)) { it.sortedDescendingBy { it.orEmpty() }} - expect(listOf("", null)) { it.sortedDescendingBy { it?.nullIfEmpty() }} + expect(listOf("", null)) { it.sortedByDescending { it.orEmpty() }} + expect(listOf("", null)) { it.sortedByDescending { it?.nullIfEmpty() }} } } diff --git a/libraries/stdlib/test/collections/SequenceTest.kt b/libraries/stdlib/test/collections/SequenceTest.kt index 38293efe3c2..2b5f61aad7f 100644 --- a/libraries/stdlib/test/collections/SequenceTest.kt +++ b/libraries/stdlib/test/collections/SequenceTest.kt @@ -323,12 +323,12 @@ public class SequenceTest { test fun sortedBy() { sequenceOf("it", "greater", "less").let { it.sortedBy { it.length() }.iterator().assertSorted { a, b -> compareValuesBy(a, b) { it.length() } <= 0 } - it.sortedDescendingBy { it.length() }.iterator().assertSorted { a, b -> compareValuesBy(a, b) { it.length() } >= 0 } + it.sortedByDescending { it.length() }.iterator().assertSorted { a, b -> compareValuesBy(a, b) { it.length() } >= 0 } } sequenceOf('a', 'd', 'c', null).let { it.sortedBy {it}.iterator().assertSorted { a, b -> compareValues(a, b) <= 0 } - it.sortedDescendingBy {it}.iterator().assertSorted { a, b -> compareValues(a, b) >= 0 } + it.sortedByDescending {it}.iterator().assertSorted { a, b -> compareValues(a, b) >= 0 } } } diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt index 3d7dafb9c9c..ee9e937500d 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt @@ -162,7 +162,7 @@ fun ordering(): List { } } - templates add f("sortedDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?)") { + templates add f("sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?)") { exclude(Strings) inline(true) returns("List") @@ -316,8 +316,8 @@ fun ordering(): List { Returns a sorted list of all elements, in descending order by results of specified [order] function. """ } - deprecate("This method may change its behavior soon. Use sortedDescendingBy() instead.") - deprecateReplacement("sortedDescendingBy(order)") + deprecate("This method may change its behavior soon. Use sortedByDescending() instead.") + deprecateReplacement("sortedByDescending(order)") returns("List") typeParam("R : Comparable") body {