From eea348768bb658e706a97620c1ebc839aaa9e0d8 Mon Sep 17 00:00:00 2001 From: Roger Willis Date: Tue, 8 Jan 2019 11:03:57 +0000 Subject: [PATCH] CORDA-2098: State pointers are now comparable. (#4494) * State pointers are now data classes, so now comparable. * Pointers now are not data classes. Implemented hashCode and equals for comparability. --- .../net/corda/core/contracts/StatePointer.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/core/src/main/kotlin/net/corda/core/contracts/StatePointer.kt b/core/src/main/kotlin/net/corda/core/contracts/StatePointer.kt index 5f1cc39401..cc31b74121 100644 --- a/core/src/main/kotlin/net/corda/core/contracts/StatePointer.kt +++ b/core/src/main/kotlin/net/corda/core/contracts/StatePointer.kt @@ -65,6 +65,19 @@ class StaticPointer(override val pointer: StateRef, override override fun resolve(ltx: LedgerTransaction): StateAndRef { return ltx.referenceInputRefsOfType(type).single { pointer == it.ref } } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is StaticPointer<*>) return false + + if (pointer != other.pointer) return false + + return true + } + + override fun hashCode(): Int { + return pointer.hashCode() + } } /** @@ -118,4 +131,17 @@ class LinearPointer(override val pointer: UniqueIdentifier, ove override fun resolve(ltx: LedgerTransaction): StateAndRef { return ltx.referenceInputRefsOfType(type).single { pointer == it.state.data.linearId } } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is LinearPointer<*>) return false + + if (pointer != other.pointer) return false + + return true + } + + override fun hashCode(): Int { + return pointer.hashCode() + } } \ No newline at end of file