From aa2805b81f055abfa3e849bf455d3ac98aa6e863 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 10 May 2020 15:34:06 +0800 Subject: [PATCH] Let ContactList implement Collection --- .../kotlin/net.mamoe.mirai/contact/ContactList.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/ContactList.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/ContactList.kt index 6560c8829..6aee51008 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/ContactList.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/ContactList.kt @@ -23,17 +23,17 @@ import kotlin.jvm.JvmField */ @Suppress("unused") class ContactList internal constructor(@JvmField internal val delegate: LockFreeLinkedList) : - Iterable { + Iterable, Collection { operator fun get(id: Long): C = delegate.asSequence().firstOrNull { it.id == id } ?: throw NoSuchElementException("Contact id $id") fun getOrNull(id: Long): C? = delegate.getOrNull(id) - val size: Int get() = delegate.size - operator fun contains(element: C): Boolean = delegate.contains(element) + override val size: Int get() = delegate.size + override operator fun contains(element: C): Boolean = delegate.contains(element) operator fun contains(id: Long): Boolean = delegate.getOrNull(id) != null - fun containsAll(elements: Collection): Boolean = elements.all { contains(it) } - fun isEmpty(): Boolean = delegate.isEmpty() + override fun containsAll(elements: Collection): Boolean = elements.all { contains(it) } + override fun isEmpty(): Boolean = delegate.isEmpty() override fun toString(): String = delegate.asSequence().joinToString(separator = ", ", prefix = "ContactList(", postfix = ")")