added a couple of helper functions to make it easier to compare values, implement Comparable and create Comparators

This commit is contained in:
James Strachan
2012-03-26 10:53:28 +01:00
parent d0e7248ec1
commit d8c3a8f55c
3 changed files with 109 additions and 9 deletions
@@ -95,15 +95,7 @@ class KDocConfig() {
protected class LongestFirstStringComparator() : Comparator<String> {
override fun compare(s1: String?, s2: String?): Int {
// TODO could we make this kind of code much easier?
if (s1 == s2) return 0
if (s1 == null) return -1
if (s2 == null) return 1
var answer = s1.length() - s2.length()
if (answer == 0) {
answer = s1.compareTo(s2)
}
return answer
return compareBy(s1, s2, { (s: String) -> s.length() })
}
override fun equals(obj : Any?) : Boolean {