diff --git a/core/src/main/kotlin/com/r3corda/core/Utils.kt b/core/src/main/kotlin/com/r3corda/core/Utils.kt index 9df261181d..80248cf812 100644 --- a/core/src/main/kotlin/com/r3corda/core/Utils.kt +++ b/core/src/main/kotlin/com/r3corda/core/Utils.kt @@ -13,7 +13,6 @@ import rx.Observable import rx.subjects.UnicastSubject import java.io.BufferedInputStream import java.io.InputStream -import java.lang.Comparable import java.math.BigDecimal import java.nio.file.Files import java.nio.file.LinkOption @@ -293,7 +292,7 @@ fun > Iterable.isOrderedAndUnique(extractId: T.() -> I): if (lastLast == null) { true } else { - lastLast.compareTo(extractId(it)) < 0 + lastLast < extractId(it) } } } \ No newline at end of file diff --git a/core/src/test/kotlin/com/r3corda/core/UtilsTest.kt b/core/src/test/kotlin/com/r3corda/core/UtilsTest.kt new file mode 100644 index 0000000000..ea3191fdab --- /dev/null +++ b/core/src/test/kotlin/com/r3corda/core/UtilsTest.kt @@ -0,0 +1,24 @@ +package com.r3corda.core + +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +class UtilsTest { + fun `ordered and unique basic`() { + val basic = listOf(1, 2, 3, 5, 8) + assertTrue(basic.isOrderedAndUnique { this }) + + val negative = listOf(-1, 2, 5) + assertTrue(negative.isOrderedAndUnique { this }) + } + + fun `ordered and unique duplicate`() { + val duplicated = listOf(1, 2, 2, 3, 5, 8) + assertFalse(duplicated.isOrderedAndUnique { this }) + } + + fun `ordered and unique out of sequence`() { + val mixed = listOf(3, 1, 2, 8, 5) + assertFalse(mixed.isOrderedAndUnique { this }) + } +} \ No newline at end of file