Deprecate 'comparator { ... }' in favor of Comparator SAM-constructor. Provide SAM-like constructor for JS.

This commit is contained in:
Ilya Gorbunov
2016-01-17 17:26:38 +03:00
parent 67ef790abc
commit 5bbce7a1de
5 changed files with 9 additions and 20 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ class OrderingTest {
@Test
fun sortComparatorThenComparator() {
val comparator = comparator<Item> { a, b -> a.name.compareTo(b.name) }.thenComparator { a, b -> a.rating.compareTo(b.rating) }
val comparator = Comparator<Item> { a, b -> a.name.compareTo(b.name) }.thenComparator { a, b -> a.rating.compareTo(b.rating) }
val diff = comparator.compare(v1, v2)
assertTrue(diff > 0)
@@ -1,7 +1,6 @@
package test.collections
import java.util.Collections
import java.util.ArrayList
import java.util.*
import kotlin.test.*
import org.junit.Test as test
@@ -13,7 +12,7 @@ class JavautilCollectionsTest {
val TEST_LIST = arrayOf(2, 0, 9, 7, 1).toList()
val SORTED_TEST_LIST = arrayOf(0, 1, 2, 7, 9).toList()
val MAX_ELEMENT = 9
val COMPARATOR = comparator { x: Int, y: Int -> if (x > y) 1 else if (x < y) -1 else 0 }
val COMPARATOR = Comparator { x: Int, y: Int -> if (x > y) 1 else if (x < y) -1 else 0 }
@test fun maxWithComparator() {
assertEquals(MAX_ELEMENT, Collections.max(TEST_LIST, COMPARATOR))