From 3eb310f3069f60582e797e7e5ee759daf0be6182 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 14 Dec 2023 15:50:19 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20equals=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hideout/activitypub/domain/model/Emoji.kt | 39 +++++++----- .../common/APResourceResolveServiceImpl.kt | 15 +++++ .../service/id/SnowflakeIdGenerateService.kt | 23 +++++++ .../core/domain/model/instance/Nodeinfo.kt | 33 ++++++++++ .../core/domain/model/instance/Nodeinfo2_0.kt | 57 +++++++++++++++++ .../HttpSignatureVerifierComposite.kt | 20 ++++++ .../springframework/oauth2/UserDetailsImpl.kt | 16 +++++ .../hideout/core/service/media/SavedMedia.kt | 63 ++++++++++++++++++- .../service/resource/KtorResolveResponse.kt | 21 +++++++ .../dev/usbharu/hideout/util/TempFileUtil.kt | 15 +++++ 10 files changed, 284 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt index a856e9a3..02fd2308 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Emoji.kt @@ -14,21 +14,6 @@ open class Emoji( HasName, HasId { - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is Emoji) return false - if (!super.equals(other)) return false - - if (updated != other.updated) return false - return icon == other.icon - } - - override fun hashCode(): Int { - var result = super.hashCode() - result = 31 * result + updated.hashCode() - result = 31 * result + icon.hashCode() - return result - } override fun toString(): String { return "Emoji(" + @@ -40,5 +25,29 @@ open class Emoji( " ${super.toString()}" } + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as Emoji + + if (name != other.name) return false + if (id != other.id) return false + if (updated != other.updated) return false + if (icon != other.icon) return false + + return true + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + name.hashCode() + result = 31 * result + id.hashCode() + result = 31 * result + updated.hashCode() + result = 31 * result + icon.hashCode() + return result + } + } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/APResourceResolveServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/APResourceResolveServiceImpl.kt index ad24ec57..b82d9df3 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/APResourceResolveServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/APResourceResolveServiceImpl.kt @@ -73,5 +73,20 @@ class APResourceResolveServiceImpl( override suspend fun statusMessage(): String { TODO("Not yet implemented") } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as APResolveResponse<*> + + return objects == other.objects + } + + override fun hashCode(): Int { + return objects.hashCode() + } + + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/application/service/id/SnowflakeIdGenerateService.kt b/src/main/kotlin/dev/usbharu/hideout/application/service/id/SnowflakeIdGenerateService.kt index dc5ab4bc..c9174a22 100644 --- a/src/main/kotlin/dev/usbharu/hideout/application/service/id/SnowflakeIdGenerateService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/application/service/id/SnowflakeIdGenerateService.kt @@ -43,4 +43,27 @@ open class SnowflakeIdGenerateService(private val baseTime: Long) : IdGenerateSe } private fun getTime(): Long = Instant.now().toEpochMilli() + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as SnowflakeIdGenerateService + + if (baseTime != other.baseTime) return false + if (lastTimeStamp != other.lastTimeStamp) return false + if (sequenceId != other.sequenceId) return false + if (mutex != other.mutex) return false + + return true + } + + override fun hashCode(): Int { + var result = baseTime.hashCode() + result = 31 * result + lastTimeStamp.hashCode() + result = 31 * result + sequenceId + result = 31 * result + mutex.hashCode() + return result + } + + } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt index f7fc3160..d22a3913 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt @@ -3,9 +3,42 @@ package dev.usbharu.hideout.core.domain.model.instance class Nodeinfo private constructor() { var links: List = emptyList() + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as Nodeinfo + + return links == other.links + } + + override fun hashCode(): Int { + return links.hashCode() + } + + } class Links private constructor() { var rel: String? = null var href: String? = null + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as Links + + if (rel != other.rel) return false + if (href != other.href) return false + + return true + } + + override fun hashCode(): Int { + var result = rel?.hashCode() ?: 0 + result = 31 * result + (href?.hashCode() ?: 0) + return result + } + + } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo2_0.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo2_0.kt index 97478228..403ab9d7 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo2_0.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo2_0.kt @@ -6,14 +6,71 @@ package dev.usbharu.hideout.core.domain.model.instance class Nodeinfo2_0 { var metadata: Metadata? = null var software: Software? = null + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as Nodeinfo2_0 + + if (metadata != other.metadata) return false + if (software != other.software) return false + + return true + } + + override fun hashCode(): Int { + var result = metadata?.hashCode() ?: 0 + result = 31 * result + (software?.hashCode() ?: 0) + return result + } + + } class Metadata { var nodeName: String? = null var nodeDescription: String? = null + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as Metadata + + if (nodeName != other.nodeName) return false + if (nodeDescription != other.nodeDescription) return false + + return true + } + + override fun hashCode(): Int { + var result = nodeName?.hashCode() ?: 0 + result = 31 * result + (nodeDescription?.hashCode() ?: 0) + return result + } + + } class Software { var name: String? = null var version: String? = null + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as Software + + if (name != other.name) return false + if (version != other.version) return false + + return true + } + + override fun hashCode(): Int { + var result = name?.hashCode() ?: 0 + result = 31 * result + (version?.hashCode() ?: 0) + return result + } + } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureVerifierComposite.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureVerifierComposite.kt index a1203ca1..a8089384 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureVerifierComposite.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureVerifierComposite.kt @@ -19,4 +19,24 @@ class HttpSignatureVerifierComposite( throw IllegalArgumentException("Unsupported algorithm. ${signature.algorithm}") } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as HttpSignatureVerifierComposite + + if (map != other.map) return false + if (httpSignatureHeaderParser != other.httpSignatureHeaderParser) return false + + return true + } + + override fun hashCode(): Int { + var result = map.hashCode() + result = 31 * result + httpSignatureHeaderParser.hashCode() + return result + } + + } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/UserDetailsImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/UserDetailsImpl.kt index dbd4e542..c5639e65 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/UserDetailsImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/UserDetailsImpl.kt @@ -38,6 +38,22 @@ class UserDetailsImpl( " ${super.toString()}" } + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as UserDetailsImpl + + return id == other.id + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + id.hashCode() + return result + } + } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/media/SavedMedia.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/media/SavedMedia.kt index 4f644da5..50a2caac 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/media/SavedMedia.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/media/SavedMedia.kt @@ -1,16 +1,73 @@ package dev.usbharu.hideout.core.service.media -sealed class SavedMedia(val success: Boolean) +sealed class SavedMedia(val success: Boolean) { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as SavedMedia + + return success == other.success + } + + override fun hashCode(): Int { + return success.hashCode() + } +} class SuccessSavedMedia( val name: String, val url: String, val thumbnailUrl: String, ) : - SavedMedia(true) + SavedMedia(true) { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as SuccessSavedMedia + + if (name != other.name) return false + if (url != other.url) return false + if (thumbnailUrl != other.thumbnailUrl) return false + + return true + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + name.hashCode() + result = 31 * result + url.hashCode() + result = 31 * result + thumbnailUrl.hashCode() + return result + } +} class FaildSavedMedia( val reason: String, val description: String, val trace: Throwable? = null -) : SavedMedia(false) +) : SavedMedia(false) { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + if (!super.equals(other)) return false + + other as FaildSavedMedia + + if (reason != other.reason) return false + if (description != other.description) return false + if (trace != other.trace) return false + + return true + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + reason.hashCode() + result = 31 * result + description.hashCode() + result = 31 * result + (trace?.hashCode() ?: 0) + return result + } +} diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/resource/KtorResolveResponse.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/resource/KtorResolveResponse.kt index 3a5e2ad1..d4f20045 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/resource/KtorResolveResponse.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/resource/KtorResolveResponse.kt @@ -28,4 +28,25 @@ class KtorResolveResponse(val ktorHttpResponse: HttpResponse) : ResolveResponse override suspend fun header(): Map> = ktorHttpResponse.headers.toMap() override suspend fun status(): Int = ktorHttpResponse.status.value override suspend fun statusMessage(): String = ktorHttpResponse.status.description + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as KtorResolveResponse + + if (ktorHttpResponse != other.ktorHttpResponse) return false + if (_bodyAsText != other._bodyAsText) return false + if (!_bodyAsBytes.contentEquals(other._bodyAsBytes)) return false + + return true + } + + override fun hashCode(): Int { + var result = ktorHttpResponse.hashCode() + result = 31 * result + _bodyAsText.hashCode() + result = 31 * result + _bodyAsBytes.contentHashCode() + return result + } + + } diff --git a/src/main/kotlin/dev/usbharu/hideout/util/TempFileUtil.kt b/src/main/kotlin/dev/usbharu/hideout/util/TempFileUtil.kt index 186aa889..6a8fbdcd 100644 --- a/src/main/kotlin/dev/usbharu/hideout/util/TempFileUtil.kt +++ b/src/main/kotlin/dev/usbharu/hideout/util/TempFileUtil.kt @@ -9,4 +9,19 @@ class TempFile(val path: T) : AutoCloseable { override fun close() { path?.let { Files.deleteIfExists(it) } } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as TempFile<*> + + return path == other.path + } + + override fun hashCode(): Int { + return path?.hashCode() ?: 0 + } + + }