Add hashCode and equals for Image, close #1302

This commit is contained in:
Karlatemp 2021-06-26 16:29:40 +08:00
parent f7170f2052
commit eb5c7414d7
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8
2 changed files with 7 additions and 14 deletions

View File

@ -219,6 +219,13 @@ public sealed class AbstractImage : Image {
override fun appendMiraiCodeTo(builder: StringBuilder) {
builder.append("[mirai:image:").append(imageId).append("]")
}
final override fun hashCode(): Int = imageId.hashCode()
final override fun equals(other: Any?): Boolean {
if (other === this) return true
if (other !is Image) return false
return this.imageId == other.imageId
}
}

View File

@ -55,13 +55,6 @@ internal class OnlineGroupImageImpl(
}/0?term=2"
} else "http://gchat.qpic.cn" + delegate.origUrl
override fun equals(other: Any?): Boolean {
return other is OnlineGroupImageImpl && other.imageId == this.imageId
}
override fun hashCode(): Int {
return imageId.hashCode() + 31 * md5.hashCode()
}
}
@Serializable(with = OnlineFriendImageImpl.Serializer::class)
@ -97,13 +90,6 @@ OnlineFriendImage() {
}
// TODO: 2020/4/24 动态获取图片下载链接的 host
override fun equals(other: Any?): Boolean {
return other is OnlineFriendImageImpl && other.imageId == this.imageId
}
override fun hashCode(): Int {
return imageId.hashCode() + 31 * md5.hashCode()
}
}
/*