Deprecate 'comparator { ... }' in favor of Comparator SAM-constructor. Provide SAM-like constructor for JS.
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user