From 7a34b11147a18974422c3919f41371fc52d52fdc Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Tue, 28 Nov 2023 11:19:27 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20Object=E3=82=92=E7=B6=99=E6=89=BF?= =?UTF-8?q?=E3=81=99=E3=82=8BJSON=E3=83=9E=E3=83=83=E3=83=94=E3=83=B3?= =?UTF-8?q?=E3=82=B0=E7=94=A8=E3=81=AEPOJO=E3=82=92Null-safe=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activitypub/domain/model/Accept.kt | 45 ++++++----- .../activitypub/domain/model/Create.kt | 57 +++++++------- .../activitypub/domain/model/Delete.kt | 27 +++++-- .../activitypub/domain/model/Document.kt | 20 ++--- .../hideout/activitypub/domain/model/Emoji.kt | 5 +- .../activitypub/domain/model/Follow.kt | 25 +++--- .../activitypub/domain/model/HasActor.kt | 5 ++ .../hideout/activitypub/domain/model/HasId.kt | 5 ++ .../activitypub/domain/model/HasName.kt | 5 ++ .../hideout/activitypub/domain/model/Image.kt | 15 ++-- .../hideout/activitypub/domain/model/Key.kt | 22 +++--- .../hideout/activitypub/domain/model/Like.kt | 33 +++++--- .../hideout/activitypub/domain/model/Note.kt | 77 +++++++------------ .../activitypub/domain/model/Person.kt | 58 ++++---------- .../activitypub/domain/model/Tombstone.kt | 27 +++++-- .../hideout/activitypub/domain/model/Undo.kt | 28 +++++-- .../domain/model/objects/Object.kt | 22 ++---- .../domain/model/objects/ObjectValue.kt | 13 ++-- 18 files changed, 258 insertions(+), 231 deletions(-) create mode 100644 src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasActor.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasId.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasName.kt diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt index c249afb4..d1b0936b 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Accept.kt @@ -1,41 +1,46 @@ package dev.usbharu.hideout.activitypub.domain.model +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.databind.annotation.JsonDeserialize import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer -open class Accept : Object { +open class Accept @JsonCreator constructor( + type: List = emptyList(), + override val name: String, @JsonDeserialize(using = ObjectDeserializer::class) @Suppress("VariableNaming") - var `object`: Object? = null - - protected constructor() - constructor( - type: List = emptyList(), - name: String, - `object`: Object?, - actor: String? - ) : super( - type = add(type, "Accept"), - name = name, - actor = actor - ) { - this.`object` = `object` - } - - override fun toString(): String = "Accept(`object`=$`object`) ${super.toString()}" + var `object`: Object?, + override val actor: String +) : Object( + type = add(type, "Accept") +), + HasActor, + HasName { override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Accept) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false - return `object` == other.`object` + other as Accept + + if (`object` != other.`object`) return false + if (actor != other.actor) return false + if (name != other.name) return false + + return true } override fun hashCode(): Int { var result = super.hashCode() result = 31 * result + (`object`?.hashCode() ?: 0) + result = 31 * result + actor.hashCode() + result = 31 * result + name.hashCode() return result } + + override fun toString(): String { + return "Accept(" + "`object`=$`object`, " + "actor='$actor', " + "name='$name'" + ")" + " ${super.toString()}" + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt index 6b19ab5b..df22045c 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Create.kt @@ -4,46 +4,51 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer -open class Create : Object { +open class Create( + type: List = emptyList(), + override val name: String, @JsonDeserialize(using = ObjectDeserializer::class) @Suppress("VariableNaming") - var `object`: Object? = null - var to: List = emptyList() + var `object`: Object?, + override val actor: String, + override val id: String, + var to: List = emptyList(), var cc: List = emptyList() - - protected constructor() : super() - constructor( - type: List = emptyList(), - name: String? = null, - `object`: Object?, - actor: String? = null, - id: String? = null, - to: List = emptyList(), - cc: List = emptyList() - ) : super( - type = add(type, "Create"), - name = name, - actor = actor, - id = id - ) { - this.`object` = `object` - this.to = to - this.cc = cc - } +) : Object( + type = add(type, "Create") +), + HasId, + HasName, + HasActor { override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Create) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false - return `object` == other.`object` + other as Create + + if (`object` != other.`object`) return false + if (to != other.to) return false + if (cc != other.cc) return false + if (name != other.name) return false + if (actor != other.actor) return false + if (id != other.id) return false + + return true } override fun hashCode(): Int { var result = super.hashCode() result = 31 * result + (`object`?.hashCode() ?: 0) + result = 31 * result + to.hashCode() + result = 31 * result + cc.hashCode() + result = 31 * result + name.hashCode() + result = 31 * result + actor.hashCode() + result = 31 * result + id.hashCode() return result } - override fun toString(): String = "Create(`object`=$`object`) ${super.toString()}" + override fun toString(): String = + "Create(`object`=$`object`, to=$to, cc=$cc, name='$name', actor='$actor', id='$id') ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt index e29e9a93..5b867818 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Delete.kt @@ -4,33 +4,42 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer -open class Delete : Object { +open class Delete : Object, HasId, HasActor, HasName { @JsonDeserialize(using = ObjectDeserializer::class) @Suppress("VariableNaming") var `object`: Object? = null var published: String? = null + override val actor: String + override val id: String + override val name: String constructor( type: List = emptyList(), - name: String? = "Delete", + name: String = "Delete", actor: String, id: String, `object`: Object, published: String? - ) : super(add(type, "Delete"), name, actor, id) { + ) : super(add(type, "Delete")) { this.`object` = `object` this.published = published + this.name = name + this.actor = actor + this.id = id } - protected constructor() : super() - override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Delete) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false + other as Delete + if (`object` != other.`object`) return false if (published != other.published) return false + if (actor != other.actor) return false + if (id != other.id) return false + if (name != other.name) return false return true } @@ -39,8 +48,12 @@ open class Delete : Object { var result = super.hashCode() result = 31 * result + (`object`?.hashCode() ?: 0) result = 31 * result + (published?.hashCode() ?: 0) + result = 31 * result + actor.hashCode() + result = 31 * result + id.hashCode() + result = 31 * result + name.hashCode() return result } - override fun toString(): String = "Delete(`object`=$`object`, published=$published) ${super.toString()}" + override fun toString(): String = + "Delete(`object`=$`object`, published=$published, actor='$actor', id='$id', name='$name') ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt index d4f70180..489029d0 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Document.kt @@ -2,34 +2,35 @@ package dev.usbharu.hideout.activitypub.domain.model import dev.usbharu.hideout.activitypub.domain.model.objects.Object -open class Document : Object { +open class Document : Object, HasName { var mediaType: String? = null var url: String? = null + override val name: String - protected constructor() : super() constructor( type: List = emptyList(), - name: String? = null, + name: String, mediaType: String, url: String ) : super( - type = add(type, "Document"), - name = name, - actor = null, - id = null + type = add(type, "Document") ) { this.mediaType = mediaType this.url = url + this.name = name } override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Document) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false + other as Document + if (mediaType != other.mediaType) return false if (url != other.url) return false + if (name != other.name) return false return true } @@ -38,8 +39,9 @@ open class Document : Object { var result = super.hashCode() result = 31 * result + (mediaType?.hashCode() ?: 0) result = 31 * result + (url?.hashCode() ?: 0) + result = 31 * result + name.hashCode() return result } - override fun toString(): String = "Document(mediaType=$mediaType, url=$url) ${super.toString()}" + override fun toString(): String = "Document(mediaType=$mediaType, url=$url, name='$name') ${super.toString()}" } 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 cce3ee87..c270be48 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 @@ -15,10 +15,7 @@ open class Emoji : Object { updated: String?, icon: Image? ) : super( - type = add(type, "Emoji"), - name = name, - actor = actor, - id = id + type = add(type, "Emoji") ) { this.updated = updated this.icon = icon diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt index 00e3eec0..73ff75f3 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Follow.kt @@ -2,37 +2,42 @@ package dev.usbharu.hideout.activitypub.domain.model import dev.usbharu.hideout.activitypub.domain.model.objects.Object -open class Follow : Object { +open class Follow : Object, HasActor { @Suppress("VariableNaming") var `object`: String? = null - protected constructor() : super() + override val actor: String + constructor( type: List = emptyList(), - name: String?, `object`: String?, - actor: String? + actor: String ) : super( - type = add(type, "Follow"), - name = name, - actor = actor + type = add(type, "Follow") ) { this.`object` = `object` + this.actor = actor } override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Follow) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false - return `object` == other.`object` + other as Follow + + if (`object` != other.`object`) return false + if (actor != other.actor) return false + + return true } override fun hashCode(): Int { var result = super.hashCode() result = 31 * result + (`object`?.hashCode() ?: 0) + result = 31 * result + actor.hashCode() return result } - override fun toString(): String = "Follow(`object`=$`object`) ${super.toString()}" + override fun toString(): String = "Follow(`object`=$`object`, actor='$actor') ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasActor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasActor.kt new file mode 100644 index 00000000..c9bc4f91 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasActor.kt @@ -0,0 +1,5 @@ +package dev.usbharu.hideout.activitypub.domain.model + +interface HasActor { + val actor: String +} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasId.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasId.kt new file mode 100644 index 00000000..774032c8 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasId.kt @@ -0,0 +1,5 @@ +package dev.usbharu.hideout.activitypub.domain.model + +interface HasId { + val id: String +} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasName.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasName.kt new file mode 100644 index 00000000..b8e4de76 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/HasName.kt @@ -0,0 +1,5 @@ +package dev.usbharu.hideout.activitypub.domain.model + +interface HasName { + val name: String +} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt index f177c8a0..60b0c8ac 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt @@ -7,9 +7,8 @@ open class Image : Object { private var url: String? = null protected constructor() : super() - constructor(type: List = emptyList(), name: String, mediaType: String?, url: String?) : super( - add(type, "Image"), - name + constructor(type: List = emptyList(), mediaType: String?, url: String?) : super( + add(type, "Image") ) { this.mediaType = mediaType this.url = url @@ -17,11 +16,15 @@ open class Image : Object { override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Image) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false + other as Image + if (mediaType != other.mediaType) return false - return url == other.url + if (url != other.url) return false + + return true } override fun hashCode(): Int { @@ -30,4 +33,6 @@ open class Image : Object { result = 31 * result + (url?.hashCode() ?: 0) return result } + + override fun toString(): String = "Image(mediaType=$mediaType, url=$url) ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt index 5cc33766..993d4af9 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Key.kt @@ -2,41 +2,45 @@ package dev.usbharu.hideout.activitypub.domain.model import dev.usbharu.hideout.activitypub.domain.model.objects.Object -open class Key : Object { +open class Key : Object, HasId { var owner: String? = null var publicKeyPem: String? = null + override val id: String - protected constructor() : super() constructor( type: List, - name: String, id: String, owner: String?, publicKeyPem: String? ) : super( - type = add(list = type, type = "Key"), - name = name, - id = id + type = add(list = type, type = "Key") ) { this.owner = owner this.publicKeyPem = publicKeyPem + this.id = id } override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Key) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false + other as Key + if (owner != other.owner) return false - return publicKeyPem == other.publicKeyPem + if (publicKeyPem != other.publicKeyPem) return false + if (id != other.id) return false + + return true } override fun hashCode(): Int { var result = super.hashCode() result = 31 * result + (owner?.hashCode() ?: 0) result = 31 * result + (publicKeyPem?.hashCode() ?: 0) + result = 31 * result + id.hashCode() return result } - override fun toString(): String = "Key(owner=$owner, publicKeyPem=$publicKeyPem) ${super.toString()}" + override fun toString(): String = "Key(owner=$owner, publicKeyPem=$publicKeyPem, id='$id') ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt index c916f566..2400eeff 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Like.kt @@ -4,42 +4,47 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer -open class Like : Object { +open class Like : Object, HasId, HasActor { @Suppress("VariableNaming") var `object`: String? = null var content: String? = null @JsonDeserialize(contentUsing = ObjectDeserializer::class) var tag: List = emptyList() + override val actor: String + override val id: String - protected constructor() : super() constructor( type: List = emptyList(), - name: String?, - actor: String?, - id: String?, + actor: String, + id: String, `object`: String?, content: String?, tag: List = emptyList() ) : super( - type = add(type, "Like"), - name = name, - actor = actor, - id = id + type = add(type, "Like") ) { this.`object` = `object` this.content = content this.tag = tag + this.actor = actor + this.id = id } override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Like) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false + other as Like + if (`object` != other.`object`) return false if (content != other.content) return false - return tag == other.tag + if (tag != other.tag) return false + if (actor != other.actor) return false + if (id != other.id) return false + + return true } override fun hashCode(): Int { @@ -47,8 +52,12 @@ open class Like : Object { result = 31 * result + (`object`?.hashCode() ?: 0) result = 31 * result + (content?.hashCode() ?: 0) result = 31 * result + tag.hashCode() + result = 31 * result + actor.hashCode() + result = 31 * result + id.hashCode() return result } - override fun toString(): String = "Like(`object`=$`object`, content=$content, tag=$tag) ${super.toString()}" + override fun toString(): String { + return "Like(`object`=$`object`, content=$content, tag=$tag, actor='$actor', id='$id') ${super.toString()}" + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt index cc891c08..74d5ce7a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Note.kt @@ -2,79 +2,58 @@ package dev.usbharu.hideout.activitypub.domain.model import dev.usbharu.hideout.activitypub.domain.model.objects.Object -open class Note : Object { - lateinit var attributedTo: String +open class Note +@Suppress("LongParameterList") +constructor( + type: List = emptyList(), + override val id: String, + var attributedTo: String, + var content: String, + var published: String, + var to: List = emptyList(), + var cc: List = emptyList(), + var sensitive: Boolean = false, + var inReplyTo: String? = null, var attachment: List = emptyList() - lateinit var content: String - lateinit var published: String - var to: List = emptyList() - var cc: List = emptyList() - var sensitive: Boolean = false - var inReplyTo: String? = null - - protected constructor() : super() - - @Suppress("LongParameterList") - constructor( - type: List = emptyList(), - name: String, - id: String?, - attributedTo: String, - content: String, - published: String, - to: List = emptyList(), - cc: List = emptyList(), - sensitive: Boolean = false, - inReplyTo: String? = null, - attachment: List = emptyList() - ) : super( - type = add(type, "Note"), - name = name, - id = id - ) { - this.attributedTo = attributedTo - this.content = content - this.published = published - this.to = to - this.cc = cc - this.sensitive = sensitive - this.inReplyTo = inReplyTo - this.attachment = attachment - } +) : Object( + type = add(type, "Note") +), + HasId { override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Note) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false + other as Note + + if (id != other.id) return false if (attributedTo != other.attributedTo) return false - if (attachment != other.attachment) return false if (content != other.content) return false if (published != other.published) return false if (to != other.to) return false if (cc != other.cc) return false if (sensitive != other.sensitive) return false if (inReplyTo != other.inReplyTo) return false + if (attachment != other.attachment) return false return true } override fun hashCode(): Int { var result = super.hashCode() - result = 31 * result + (attributedTo?.hashCode() ?: 0) - result = 31 * result + attachment.hashCode() - result = 31 * result + (content?.hashCode() ?: 0) - result = 31 * result + (published?.hashCode() ?: 0) + result = 31 * result + id.hashCode() + result = 31 * result + attributedTo.hashCode() + result = 31 * result + content.hashCode() + result = 31 * result + published.hashCode() result = 31 * result + to.hashCode() result = 31 * result + cc.hashCode() result = 31 * result + sensitive.hashCode() result = 31 * result + (inReplyTo?.hashCode() ?: 0) + result = 31 * result + attachment.hashCode() return result } - override fun toString(): String { - return "Note(attributedTo=$attributedTo, attachment=$attachment, " + - "content=$content, published=$published, to=$to, cc=$cc, sensitive=$sensitive," + - " inReplyTo=$inReplyTo) ${super.toString()}" - } + override fun toString(): String = + "Note(id='$id', attributedTo='$attributedTo', content='$content', published='$published', to=$to, cc=$cc, sensitive=$sensitive, inReplyTo=$inReplyTo, attachment=$attachment) ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt index 7ee0075e..e94cc9b1 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt @@ -2,47 +2,23 @@ package dev.usbharu.hideout.activitypub.domain.model import dev.usbharu.hideout.activitypub.domain.model.objects.Object -open class Person : Object { - var preferredUsername: String? = null - var summary: String? = null - var inbox: String? = null - var outbox: String? = null - var url: String? = null - private var icon: Image? = null - var publicKey: Key? = null - var endpoints: Map = emptyMap() - var following: String? = null - var followers: String? = null - - protected constructor() : super() - - @Suppress("LongParameterList") - constructor( - type: List = emptyList(), - name: String, - id: String?, - preferredUsername: String?, - summary: String?, - inbox: String?, - outbox: String?, - url: String?, - icon: Image?, - publicKey: Key?, - endpoints: Map = emptyMap(), - followers: String?, - following: String? - ) : super(add(type, "Person"), name, id = id) { - this.preferredUsername = preferredUsername - this.summary = summary - this.inbox = inbox - this.outbox = outbox - this.url = url - this.icon = icon - this.publicKey = publicKey - this.endpoints = endpoints - this.followers = followers - this.following = following - } +open class Person +@Suppress("LongParameterList") +constructor( + type: List = emptyList(), + override val name: String, + override val id: String, + var preferredUsername: String?, + var summary: String?, + var inbox: String?, + var outbox: String?, + var url: String?, + private var icon: Image?, + var publicKey: Key?, + var endpoints: Map = emptyMap(), + var followers: String?, + var following: String? +) : Object(add(type, "Person")), HasId, HasName { override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Tombstone.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Tombstone.kt index 0017eac4..201eba32 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Tombstone.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Tombstone.kt @@ -2,11 +2,24 @@ package dev.usbharu.hideout.activitypub.domain.model import dev.usbharu.hideout.activitypub.domain.model.objects.Object -open class Tombstone : Object { - constructor( - type: List = emptyList(), - name: String = "Tombstone", - actor: String? = null, - id: String - ) : super(add(type, "Tombstone"), name, actor, id) +open class Tombstone(type: List = emptyList(), override val id: String) : + Object(add(type, "Tombstone")), + HasId { + 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 Tombstone + + return id == other.id + } + + override fun hashCode(): Int { + var result = super.hashCode() + result = 31 * result + id.hashCode() + return result + } + + override fun toString(): String = "Tombstone(id='$id') ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt index a8fbb65a..f1a0d9d6 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt @@ -5,41 +5,53 @@ import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer import java.time.Instant -open class Undo : Object { +open class Undo : Object, HasId, HasActor { @JsonDeserialize(using = ObjectDeserializer::class) @Suppress("VariableNaming") var `object`: Object? = null var published: String? = null + override val actor: String + override val id: String - protected constructor() : super() constructor( type: List = emptyList(), - name: String, actor: String, - id: String?, + id: String, `object`: Object, published: Instant - ) : super(add(type, "Undo"), name, actor, id) { + ) : super(add(type, "Undo")) { this.`object` = `object` this.published = published.toString() + this.id = id + this.actor = actor } override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Undo) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false + other as Undo + if (`object` != other.`object`) return false - return published == other.published + if (published != other.published) return false + if (actor != other.actor) return false + if (id != other.id) return false + + return true } override fun hashCode(): Int { var result = super.hashCode() result = 31 * result + (`object`?.hashCode() ?: 0) result = 31 * result + (published?.hashCode() ?: 0) + result = 31 * result + actor.hashCode() + result = 31 * result + id.hashCode() return result } - override fun toString(): String = "Undo(`object`=$`object`, published=$published) ${super.toString()}" + override fun toString(): String { + return "Undo(`object`=$`object`, published=$published, actor='$actor', id='$id') ${super.toString()}" + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/Object.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/Object.kt index 23f26eac..cafdb44d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/Object.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/Object.kt @@ -12,41 +12,29 @@ open class Object : JsonLd { set(value) { field = value.filter { it.isNotBlank() } } - var name: String? = null - var actor: String? = null - var id: String? = null protected constructor() - constructor(type: List, name: String? = null, actor: String? = null, id: String? = null) : super() { + constructor(type: List) : super() { this.type = type.filter { it.isNotBlank() } - this.name = name - this.actor = actor - this.id = id } override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is Object) return false + if (javaClass != other?.javaClass) return false if (!super.equals(other)) return false - if (type != other.type) return false - if (name != other.name) return false - if (actor != other.actor) return false - if (id != other.id) return false + other as Object - return true + return type == other.type } override fun hashCode(): Int { var result = super.hashCode() result = 31 * result + type.hashCode() - result = 31 * result + (name?.hashCode() ?: 0) - result = 31 * result + (actor?.hashCode() ?: 0) - result = 31 * result + (id?.hashCode() ?: 0) return result } - override fun toString(): String = "Object(type=$type, name=$name, actor=$actor, id=$id) ${super.toString()}" + override fun toString(): String = "Object(type=$type) ${super.toString()}" companion object { @JvmStatic diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectValue.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectValue.kt index b97b2541..2a9c8eef 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectValue.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectValue.kt @@ -1,16 +1,15 @@ package dev.usbharu.hideout.activitypub.domain.model.objects +import com.fasterxml.jackson.annotation.JsonCreator + @Suppress("VariableNaming") open class ObjectValue : Object { - var `object`: String? = null + lateinit var `object`: String - protected constructor() : super() - constructor(type: List, name: String?, actor: String?, id: String?, `object`: String?) : super( - type, - name, - actor, - id + @JsonCreator + constructor(type: List) : super( + type ) { this.`object` = `object` }