From f34ef6aabffa0e092200a23a565c538dea16bcfa Mon Sep 17 00:00:00 2001 From: Alex Plate Date: Fri, 8 May 2020 18:01:46 +0300 Subject: [PATCH] [Workspace Model] Use custom equals/hashCode for PId GitOrigin-RevId: 114e71f2126d9056613585c3b90e887f6f5f3376 --- .../src/pstorage/Entities.kt | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/platform/workspaceModel-core/src/pstorage/Entities.kt b/platform/workspaceModel-core/src/pstorage/Entities.kt index 0c80ce8cd159..555c029f818a 100644 --- a/platform/workspaceModel-core/src/pstorage/Entities.kt +++ b/platform/workspaceModel-core/src/pstorage/Entities.kt @@ -79,7 +79,25 @@ internal data class PId(val arrayId: Int, val clazz: KClass) if (arrayId < 0) error("ArrayId cannot be negative: $arrayId") } - override fun toString(): String = clazz.simpleName + "-:-"+ arrayId.toString() + override fun toString(): String = clazz.simpleName + "-:-" + arrayId.toString() + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as PId<*> + + if (arrayId != other.arrayId) return false + if (clazz.java != other.clazz.java) return false + + return true + } + + override fun hashCode(): Int { + var result = arrayId + result = 31 * result + clazz.java.hashCode() + return result + } } interface PSoftLinkable {