Avoid using negative in descending sorts.

This commit is contained in:
Ilya Ryzhenkov
2014-11-05 17:41:29 +03:00
parent 55590e00a5
commit 0dc68c2702
2 changed files with 5 additions and 5 deletions
+3 -3
View File
@@ -156,7 +156,7 @@ public inline fun <T, R : Comparable<R>> Iterable<T>.sortBy(inlineOptions(Inline
*/
public fun <T : Comparable<T>> Iterable<T>.sortDescending(): List<T> {
val sortedList = toArrayList()
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> -x.compareTo(y) }
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> y.compareTo(x) }
java.util.Collections.sort(sortedList, sortBy)
return sortedList
}
@@ -166,7 +166,7 @@ public fun <T : Comparable<T>> Iterable<T>.sortDescending(): List<T> {
*/
public inline fun <T, R : Comparable<R>> Array<out T>.sortDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R): List<T> {
val sortedList = toArrayList()
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> -order(x).compareTo(order(y)) }
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> order(y).compareTo(order(x)) }
java.util.Collections.sort(sortedList, sortBy)
return sortedList
}
@@ -176,7 +176,7 @@ public inline fun <T, R : Comparable<R>> Array<out T>.sortDescendingBy(inlineOpt
*/
public inline fun <T, R : Comparable<R>> Iterable<T>.sortDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R): List<T> {
val sortedList = toArrayList()
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> -order(x).compareTo(order(y)) }
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> order(y).compareTo(order(x)) }
java.util.Collections.sort(sortedList, sortBy)
return sortedList
}
@@ -80,7 +80,7 @@ fun ordering(): List<GenericFunction> {
body {
"""
val sortedList = toArrayList()
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> -x.compareTo(y) }
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> y.compareTo(x) }
java.util.Collections.sort(sortedList, sortBy)
return sortedList
"""
@@ -150,7 +150,7 @@ fun ordering(): List<GenericFunction> {
body {
"""
val sortedList = toArrayList()
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> -order(x).compareTo(order(y)) }
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) -> order(y).compareTo(order(x)) }
java.util.Collections.sort(sortedList, sortBy)
return sortedList
"""