diff --git a/libraries/stdlib/src/generated/_Arrays.kt b/libraries/stdlib/src/generated/_Arrays.kt index 809fb2dc46b..2110e1de8eb 100644 --- a/libraries/stdlib/src/generated/_Arrays.kt +++ b/libraries/stdlib/src/generated/_Arrays.kt @@ -4477,76 +4477,151 @@ public fun ShortArray.reversedArray(): ShortArray { return result } +/** + * Sorts elements in the array in-place according to natural sort order of the value returned by specified [selector] function. + */ +public inline fun > Array.sortBy(crossinline selector: (T) -> R?): Unit { + if (size > 1) sortWith(compareBy(selector)) +} + +/** + * Sorts elements in the array in-place descending according to natural sort order of the value returned by specified [selector] function. + */ +public inline fun > Array.sortByDescending(crossinline selector: (T) -> R?): Unit { + if (size > 1) sortWith(compareByDescending(selector)) +} + +/** + * Sorts elements in the array in-place descending according to their natural sort order. + */ +public fun > Array.sortDescending(): Unit { + sortWith(reverseOrder()) +} + +/** + * Sorts elements in the array in-place descending according to their natural sort order. + */ +public fun ByteArray.sortDescending(): Unit { + if (size > 1) { + sort() + reverse() + } +} + +/** + * Sorts elements in the array in-place descending according to their natural sort order. + */ +public fun CharArray.sortDescending(): Unit { + if (size > 1) { + sort() + reverse() + } +} + +/** + * Sorts elements in the array in-place descending according to their natural sort order. + */ +public fun DoubleArray.sortDescending(): Unit { + if (size > 1) { + sort() + reverse() + } +} + +/** + * Sorts elements in the array in-place descending according to their natural sort order. + */ +public fun FloatArray.sortDescending(): Unit { + if (size > 1) { + sort() + reverse() + } +} + +/** + * Sorts elements in the array in-place descending according to their natural sort order. + */ +public fun IntArray.sortDescending(): Unit { + if (size > 1) { + sort() + reverse() + } +} + +/** + * Sorts elements in the array in-place descending according to their natural sort order. + */ +public fun LongArray.sortDescending(): Unit { + if (size > 1) { + sort() + reverse() + } +} + +/** + * Sorts elements in the array in-place descending according to their natural sort order. + */ +public fun ShortArray.sortDescending(): Unit { + if (size > 1) { + sort() + reverse() + } +} + /** * Returns a list of all elements sorted according to their natural sort order. */ public fun > Array.sorted(): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList) - return sortedList + return toArrayList().apply { sort() } } /** * Returns a list of all elements sorted according to their natural sort order. */ public fun ByteArray.sorted(): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList) - return sortedList + return toArrayList().apply { sort() } } /** * Returns a list of all elements sorted according to their natural sort order. */ public fun CharArray.sorted(): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList) - return sortedList + return toArrayList().apply { sort() } } /** * Returns a list of all elements sorted according to their natural sort order. */ public fun DoubleArray.sorted(): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList) - return sortedList + return toArrayList().apply { sort() } } /** * Returns a list of all elements sorted according to their natural sort order. */ public fun FloatArray.sorted(): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList) - return sortedList + return toArrayList().apply { sort() } } /** * Returns a list of all elements sorted according to their natural sort order. */ public fun IntArray.sorted(): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList) - return sortedList + return toArrayList().apply { sort() } } /** * Returns a list of all elements sorted according to their natural sort order. */ public fun LongArray.sorted(): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList) - return sortedList + return toArrayList().apply { sort() } } /** * Returns a list of all elements sorted according to their natural sort order. */ public fun ShortArray.sorted(): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList) - return sortedList + return toArrayList().apply { sort() } } /** @@ -4618,8 +4693,7 @@ public fun ShortArray.sortedArray(): ShortArray { */ public fun > Array.sortedArrayDescending(): Array { if (isEmpty()) return this - // TODO: Use reverseOrder() - return this.copyOf().apply { sortWith(comparator { a, b -> b.compareTo(a) }) } + return this.copyOf().apply { sortWith(reverseOrder()) } } /** @@ -4627,8 +4701,7 @@ public fun > Array.sortedArrayDescending(): Array> ShortArray.sortedByDescending(crossinline * Returns a list of all elements sorted descending according to their natural sort order. */ public fun > Array.sortedDescending(): List { - return sortedWith(comparator { x, y -> y.compareTo(x) }) + return sortedWith(reverseOrder()) } /** @@ -4879,81 +4946,63 @@ public fun ShortArray.sortedDescending(): List { * Returns a list of all elements sorted according to the specified [comparator]. */ public fun Array.sortedWith(comparator: Comparator): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList, comparator) - return sortedList + return toArrayList().apply { sortWith(comparator) } } /** * Returns a list of all elements sorted according to the specified [comparator]. */ public fun BooleanArray.sortedWith(comparator: Comparator): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList, comparator) - return sortedList + return toArrayList().apply { sortWith(comparator) } } /** * Returns a list of all elements sorted according to the specified [comparator]. */ public fun ByteArray.sortedWith(comparator: Comparator): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList, comparator) - return sortedList + return toArrayList().apply { sortWith(comparator) } } /** * Returns a list of all elements sorted according to the specified [comparator]. */ public fun CharArray.sortedWith(comparator: Comparator): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList, comparator) - return sortedList + return toArrayList().apply { sortWith(comparator) } } /** * Returns a list of all elements sorted according to the specified [comparator]. */ public fun DoubleArray.sortedWith(comparator: Comparator): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList, comparator) - return sortedList + return toArrayList().apply { sortWith(comparator) } } /** * Returns a list of all elements sorted according to the specified [comparator]. */ public fun FloatArray.sortedWith(comparator: Comparator): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList, comparator) - return sortedList + return toArrayList().apply { sortWith(comparator) } } /** * Returns a list of all elements sorted according to the specified [comparator]. */ public fun IntArray.sortedWith(comparator: Comparator): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList, comparator) - return sortedList + return toArrayList().apply { sortWith(comparator) } } /** * Returns a list of all elements sorted according to the specified [comparator]. */ public fun LongArray.sortedWith(comparator: Comparator): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList, comparator) - return sortedList + return toArrayList().apply { sortWith(comparator) } } /** * Returns a list of all elements sorted according to the specified [comparator]. */ public fun ShortArray.sortedWith(comparator: Comparator): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList, comparator) - return sortedList + return toArrayList().apply { sortWith(comparator) } } /** diff --git a/libraries/stdlib/src/generated/_Collections.kt b/libraries/stdlib/src/generated/_Collections.kt index ecb3d069433..d4da6b525fa 100644 --- a/libraries/stdlib/src/generated/_Collections.kt +++ b/libraries/stdlib/src/generated/_Collections.kt @@ -806,13 +806,32 @@ public fun Iterable.reversed(): List { return list } +/** + * Sorts elements in the collection in-place according to natural sort order of the value returned by specified [selector] function. + */ +public inline fun > MutableList.sortBy(crossinline selector: (T) -> R?): Unit { + if (size > 1) sortWith(compareBy(selector)) +} + +/** + * Sorts elements in the collection in-place descending according to natural sort order of the value returned by specified [selector] function. + */ +public inline fun > MutableList.sortByDescending(crossinline selector: (T) -> R?): Unit { + if (size > 1) sortWith(compareByDescending(selector)) +} + +/** + * Sorts elements in the collection in-place descending according to their natural sort order. + */ +public fun > MutableList.sortDescending(): Unit { + sortWith(reverseOrder()) +} + /** * Returns a list of all elements sorted according to their natural sort order. */ public fun > Iterable.sorted(): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList) - return sortedList + return toArrayList().apply { sort() } } /** @@ -833,16 +852,14 @@ public inline fun > Iterable.sortedByDescending(crossinl * Returns a list of all elements sorted descending according to their natural sort order. */ public fun > Iterable.sortedDescending(): List { - return sortedWith(comparator { x, y -> y.compareTo(x) }) + return sortedWith(reverseOrder()) } /** * Returns a list of all elements sorted according to the specified [comparator]. */ public fun Iterable.sortedWith(comparator: Comparator): List { - val sortedList = toArrayList() - java.util.Collections.sort(sortedList, comparator) - return sortedList + return toArrayList().apply { sortWith(comparator) } } /** diff --git a/libraries/stdlib/src/generated/_Sequences.kt b/libraries/stdlib/src/generated/_Sequences.kt index 72cc214a20a..8096517d672 100644 --- a/libraries/stdlib/src/generated/_Sequences.kt +++ b/libraries/stdlib/src/generated/_Sequences.kt @@ -422,7 +422,7 @@ public fun > Sequence.sorted(): Sequence { return object : Sequence { override fun iterator(): Iterator { val sortedList = this@sorted.toArrayList() - java.util.Collections.sort(sortedList) + sortedList.sort() return sortedList.iterator() } } @@ -446,7 +446,7 @@ public inline fun > Sequence.sortedByDescending(crossinl * Returns a sequence that yields elements of this sequence sorted descending according to their natural sort order. */ public fun > Sequence.sortedDescending(): Sequence { - return sortedWith(comparator { x, y -> y.compareTo(x) }) + return sortedWith(reverseOrder()) } /** @@ -456,7 +456,7 @@ public fun Sequence.sortedWith(comparator: Comparator): Sequence return object : Sequence { override fun iterator(): Iterator { val sortedList = this@sortedWith.toArrayList() - java.util.Collections.sort(sortedList, comparator) + sortedList.sortWith(comparator) return sortedList.iterator() } } diff --git a/libraries/stdlib/src/kotlin/collections/MutableCollections.kt b/libraries/stdlib/src/kotlin/collections/MutableCollections.kt index ce71378f088..30d70cc7a9f 100644 --- a/libraries/stdlib/src/kotlin/collections/MutableCollections.kt +++ b/libraries/stdlib/src/kotlin/collections/MutableCollections.kt @@ -3,6 +3,8 @@ package kotlin +import java.util.* + /** * Checks if all elements in the specified collection are contained in this collection. * @@ -247,3 +249,17 @@ public fun MutableCollection.retainAll(sequence: Sequence) { else clear() } + +/** + * Sorts elements in the list in-place according to their natural sort order. + * */ +public fun > MutableList.sort(): Unit { + if (size > 1) java.util.Collections.sort(this) +} + +/** + * Sorts elements in the list in-place according to order specified with [comparator]. + */ +public fun MutableList.sortWith(comparator: Comparator): Unit { + if (size > 1) java.util.Collections.sort(this, comparator) +} diff --git a/libraries/stdlib/test/collections/ArraysTest.kt b/libraries/stdlib/test/collections/ArraysTest.kt index 7415d7312a0..55ea5f05790 100644 --- a/libraries/stdlib/test/collections/ArraysTest.kt +++ b/libraries/stdlib/test/collections/ArraysTest.kt @@ -823,25 +823,34 @@ class ArraysTest { val intArr = intArrayOf(5, 2, 1, 9, 80, Int.MIN_VALUE, Int.MAX_VALUE) intArr.sort() assertArrayNotSameButEquals(intArrayOf(Int.MIN_VALUE, 1, 2, 5, 9, 80, Int.MAX_VALUE), intArr) + intArr.sortDescending() + assertArrayNotSameButEquals(intArrayOf(Int.MAX_VALUE, 80, 9, 5, 2, 1, Int.MIN_VALUE), intArr) val longArr = longArrayOf(200, 2, 1, 4, 3, Long.MIN_VALUE, Long.MAX_VALUE) longArr.sort() assertArrayNotSameButEquals(longArrayOf(Long.MIN_VALUE, 1, 2, 3, 4, 200, Long.MAX_VALUE), longArr) + longArr.sortDescending() + assertArrayNotSameButEquals(longArrayOf(Long.MAX_VALUE, 200, 4, 3, 2, 1, Long.MIN_VALUE), longArr) val charArr = charArrayOf('d', 'c', 'E', 'a', '\u0000', '\uFFFF') charArr.sort() assertArrayNotSameButEquals(charArrayOf('\u0000', 'E', 'a', 'c', 'd', '\uFFFF'), charArr) + charArr.sortDescending() + assertArrayNotSameButEquals(charArrayOf('\uFFFF', 'd', 'c', 'a', 'E', '\u0000'), charArr) + val strArr = arrayOf("9", "80", "all", "Foo") strArr.sort() assertArrayNotSameButEquals(arrayOf("80", "9", "Foo", "all"), strArr) + strArr.sortDescending() + assertArrayNotSameButEquals(arrayOf("all", "Foo", "9", "80"), strArr) } @test fun sorted() { assertTrue(arrayOf().sorted().none()) assertEquals(listOf(1), arrayOf(1).sorted()) - fun arrayData>(vararg values: T, toArray: Array.() -> A) = ArraySortedChecker(values.toArray(), comparator { a, b -> a.compareTo(b) }) + fun arrayData>(vararg values: T, toArray: Array.() -> A) = ArraySortedChecker(values.toArray(), naturalOrder()) with (arrayData("ac", "aD", "aba") { toList().toTypedArray() }) { checkSorted>({ sorted() }, { sortedDescending() }, { iterator() }) @@ -875,6 +884,18 @@ class ArraysTest { } } + @test fun sortByInPlace() { + val data = arrayOf("aa" to 20, "ab" to 3, "aa" to 3) + data.sortBy { it.second } + assertArrayNotSameButEquals(arrayOf("ab" to 3, "aa" to 3, "aa" to 20), data) + + data.sortBy { it.first } + assertArrayNotSameButEquals(arrayOf("aa" to 3, "aa" to 20, "ab" to 3), data) + + data.sortByDescending { (it.first + it.second).length } + assertArrayNotSameButEquals(arrayOf("aa" to 20, "aa" to 3, "ab" to 3), data) + } + @test fun sortedBy() { val values = arrayOf("ac", "aD", "aba") val indices = values.indices.toList().toIntArray() @@ -900,11 +921,16 @@ class ArraysTest { arrayData(arrayOf(0, 1, 2, 3, 4, 5), comparator) .checkSorted>( { sortedArrayWith(comparator) }, { sortedArrayWith(comparator.reversed()) }, { iterator() }) + + // in-place + val array = Array(6) { it } + array.sortWith(comparator) + array.iterator().assertSorted { a, b -> comparator.compare(a, b) <= 0 } } } private class ArraySortedChecker(val array: A, val comparator: Comparator) { - public fun checkSorted(sorted: A.() -> R, sortedDescending: A.() -> R, iterator: R.() -> Iterator) { + public fun checkSorted(sorted: A.() -> R, sortedDescending: A.() -> R, iterator: R.() -> Iterator) { array.sorted().iterator().assertSorted { a, b -> comparator.compare(a, b) <= 0 } array.sortedDescending().iterator().assertSorted { a, b -> comparator.compare(a, b) >= 0 } } diff --git a/libraries/stdlib/test/collections/CollectionTest.kt b/libraries/stdlib/test/collections/CollectionTest.kt index f3f18b83f46..7105685882d 100644 --- a/libraries/stdlib/test/collections/CollectionTest.kt +++ b/libraries/stdlib/test/collections/CollectionTest.kt @@ -563,16 +563,40 @@ class CollectionTest { expect(listOf(1)) { listOf(1) take 10 } } + @test fun sortInPlace() { + val data = listOf(11, 3, 7) + + val asc = data.toArrayList() + asc.sort() + assertEquals(listOf(3, 7, 11), asc) + + val desc = data.toArrayList() + desc.sortDescending() + assertEquals(listOf(11, 7, 3), desc) + } + @test fun sorted() { val data = listOf(11, 3, 7) assertEquals(listOf(3, 7, 11), data.sorted()) assertEquals(listOf(11, 7, 3), data.sortedDescending()) } + @test fun sortByInPlace() { + val data = arrayListOf("aa" to 20, "ab" to 3, "aa" to 3) + data.sortBy { it.second } + assertEquals(listOf("ab" to 3, "aa" to 3, "aa" to 20), data) + + data.sortBy { it.first } + assertEquals(listOf("aa" to 3, "aa" to 20, "ab" to 3), data) + + data.sortByDescending { (it.first + it.second).length } + assertEquals(listOf("aa" to 20, "aa" to 3, "ab" to 3), data) + } + @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").sortedByDescending { it.length() }) + assertEquals(listOf("two" to 3, "three" to 20), listOf("three" to 20, "two" to 3).sortedBy { it.second }) + assertEquals(listOf("three" to 20, "two" to 3), listOf("three" to 20, "two" to 3).sortedBy { it.first }) + assertEquals(listOf("three", "two"), listOf("two", "three").sortedByDescending { it.length }) } @test fun sortedNullableBy() { diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt index 490d96e58fd..46d20ccd730 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt @@ -99,9 +99,7 @@ fun ordering(): List { typeParam("T : Comparable") body { """ - val sortedList = toArrayList() - java.util.Collections.sort(sortedList) - return sortedList + return toArrayList().apply { sort() } """ } @@ -114,7 +112,7 @@ fun ordering(): List { return object : Sequence { override fun iterator(): Iterator { val sortedList = this@sorted.toArrayList() - java.util.Collections.sort(sortedList) + sortedList.sort() return sortedList.iterator() } } @@ -138,6 +136,25 @@ fun ordering(): List { } } + templates add f("sortDescending()") { + only(Lists, ArraysOfObjects, ArraysOfPrimitives) + exclude(PrimitiveType.Boolean) + doc { f -> """Sorts elements in the ${f.collection} in-place descending according to their natural sort order.""" } + returns("Unit") + typeParam("T : Comparable") + customReceiver(Lists) { "MutableList" } + + body { """sortWith(reverseOrder())""" } + body(ArraysOfPrimitives) { + """ + if (size > 1) { + sort() + reverse() + } + """ + } + } + templates add f("sortedDescending()") { exclude(PrimitiveType.Boolean) @@ -150,7 +167,7 @@ fun ordering(): List { typeParam("T : Comparable") body { """ - return sortedWith(comparator { x, y -> y.compareTo(x) }) + return sortedWith(reverseOrder()) """ } body(ArraysOfPrimitives) { @@ -163,11 +180,6 @@ fun ordering(): List { doc(Sequences) { "Returns a sequence that yields elements of this sequence sorted descending according to their natural sort order." } - body(Sequences) { - """ - return sortedWith(comparator { x, y -> y.compareTo(x) }) - """ - } } templates add f("sortedArrayDescending()") { @@ -181,16 +193,14 @@ fun ordering(): List { body(ArraysOfObjects) { """ if (isEmpty()) return this - // TODO: Use reverseOrder() - return this.copyOf().apply { sortWith(comparator { a, b -> b.compareTo(a) }) } + return this.copyOf().apply { sortWith(reverseOrder()) } """ } body() { """ if (isEmpty()) return this - // TODO: Use in-place reverse - return this.copyOf().apply { sort() }.reversedArray() + return this.copyOf().apply { sortDescending() } """ } } @@ -204,9 +214,7 @@ fun ordering(): List { } body { """ - val sortedList = toArrayList() - java.util.Collections.sort(sortedList, comparator) - return sortedList + return toArrayList().apply { sortWith(comparator) } """ } @@ -219,7 +227,7 @@ fun ordering(): List { return object : Sequence { override fun iterator(): Iterator { val sortedList = this@sortedWith.toArrayList() - java.util.Collections.sort(sortedList, comparator) + sortedList.sortWith(comparator) return sortedList.iterator() } } @@ -241,6 +249,17 @@ fun ordering(): List { } } + templates add f("sortBy(crossinline selector: (T) -> R?)") { + inline(true) + only(Lists, ArraysOfObjects) + doc { f -> """Sorts elements in the ${f.collection} in-place according to natural sort order of the value returned by specified [selector] function.""" } + returns("Unit") + typeParam("R : Comparable") + customReceiver(Lists) { "MutableList" } + + body { """if (size > 1) sortWith(compareBy(selector))""" } + } + templates add f("sortedBy(crossinline selector: (T) -> R?)") { inline(true) returns("List") @@ -262,6 +281,18 @@ fun ordering(): List { } } + templates add f("sortByDescending(crossinline selector: (T) -> R?)") { + inline(true) + only(Lists, ArraysOfObjects) + doc { f -> """Sorts elements in the ${f.collection} in-place descending according to natural sort order of the value returned by specified [selector] function.""" } + returns("Unit") + typeParam("R : Comparable") + customReceiver(Lists) { "MutableList" } + + body { + """if (size > 1) sortWith(compareByDescending(selector))""" } + } + templates add f("sortedByDescending(crossinline selector: (T) -> R?)") { inline(true) returns("List") @@ -283,128 +314,5 @@ fun ordering(): List { } } -// templates add f("sort()") { -// doc { -// """ -// Returns a sorted list of all elements. -// """ -// } -// returns("List") -// typeParam("T : Comparable") -// deprecate("This method may change its behavior soon. Use sorted() instead.") -// deprecateReplacement("sorted()") -// body { -// """ -// val sortedList = toArrayList() -// java.util.Collections.sort(sortedList) -// return sortedList -// """ -// } -// -// exclude(Sequences) -// exclude(ArraysOfPrimitives) -// exclude(ArraysOfObjects) -// exclude(Strings) -// } - -// templates add f("sortDescending()") { -// doc { -// """ -// Returns a sorted list of all elements, in descending order. -// """ -// } -// deprecate("This method may change its behavior soon. Use sortedDescending() instead.") -// deprecateReplacement("sortedDescending()") -// returns("List") -// typeParam("T : Comparable") -// body { -// """ -// val sortedList = toArrayList() -// java.util.Collections.sort(sortedList, comparator { x, y -> y.compareTo(x) }) -// return sortedList -// """ -// } -// -// exclude(Sequences) -// exclude(ArraysOfPrimitives) -// exclude(ArraysOfObjects) -// exclude(Strings) -// } - -// templates add f("sortBy(crossinline order: (T) -> R)") { -// inline(true) -// -// doc { -// """ -// Returns a sorted list of all elements, ordered by results of specified [order] function. -// """ -// } -// deprecate("This method may change its behavior soon. Use sortedBy() instead.") -// deprecateReplacement("sortedBy(order)") -// returns("List") -// typeParam("R : Comparable") -// body { -// """ -// val sortedList = toArrayList() -// val sortBy: Comparator = compareBy(order) -// java.util.Collections.sort(sortedList, sortBy) -// return sortedList -// """ -// } -// -// exclude(Sequences) -// exclude(ArraysOfPrimitives) -// exclude(Strings) -// } - - -// templates add f("sortDescendingBy(crossinline order: (T) -> R)") { -// inline(true) -// -// doc { -// """ -// 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 sortedByDescending() instead.") -// deprecateReplacement("sortedByDescending(order)") -// returns("List") -// typeParam("R : Comparable") -// body { -// """ -// val sortedList = toArrayList() -// val sortBy: Comparator = compareByDescending(order) -// java.util.Collections.sort(sortedList, sortBy) -// return sortedList -// """ -// } -// -// exclude(Sequences) -// exclude(ArraysOfPrimitives) -// exclude(Strings) -// } - -// templates add f("sortBy(comparator: Comparator)") { -// doc { -// """ -// Returns a list of all elements, sorted by the specified [comparator]. -// """ -// } -// returns("List") -// deprecate("This method may change its behavior soon. Use sortedWith() instead.") -// deprecateReplacement("sortedWith(comparator)") -// body { -// """ -// val sortedList = toArrayList() -// java.util.Collections.sort(sortedList, comparator) -// return sortedList -// """ -// } -// -// exclude(Sequences) -// exclude(ArraysOfPrimitives) -// exclude(Strings) -// } - return templates } \ No newline at end of file