tidied up the compareBy helper function a little; only compare based on the functions given
This commit is contained in:
@@ -95,7 +95,7 @@ class KDocConfig() {
|
||||
|
||||
protected class LongestFirstStringComparator() : Comparator<String> {
|
||||
override fun compare(s1: String?, s2: String?): Int {
|
||||
return compareBy(s1, s2, { (s: String) -> s.length() })
|
||||
return compareBy(s1, s2, { (s: String) -> s.length() }, { (s: String) -> s })
|
||||
}
|
||||
|
||||
override fun equals(obj : Any?) : Boolean {
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package kotlin
|
||||
|
||||
import java.lang.Iterable
|
||||
import java.util.Comparator
|
||||
import java.util.Comparator
|
||||
|
||||
/**
|
||||
* Helper method for implementing [[Comparable<T>]] methods using a list of functions
|
||||
* to calculate the values to compare
|
||||
*/
|
||||
inline fun <T> compareBy(a: T?, b: T?, vararg functions: Function1<T,Any?>): Int {
|
||||
* Helper method for implementing [[Comparable<T>]] methods using a list of functions
|
||||
* to calculate the values to compare
|
||||
*/
|
||||
inline fun <T> compareBy(a: T?, b: T?, vararg functions: Function1<T, Any?>): Int {
|
||||
require(functions.size > 0)
|
||||
if (a === b) return 0
|
||||
if (a == null) return - 1
|
||||
if (b == null) return 1
|
||||
@@ -18,7 +17,7 @@ inline fun <T> compareBy(a: T?, b: T?, vararg functions: Function1<T,Any?>): Int
|
||||
val diff = compareValues(v1, v2)
|
||||
if (diff != null) return diff
|
||||
}
|
||||
return compareValues(a, b)
|
||||
return 0
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user