From e8b0c99006bf93b800a948bf955e9673018ea831 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 4 Apr 2020 13:54:11 +0800 Subject: [PATCH] Fix name --- .../net/mamoe/mirai/qqandroid/contact/GroupImpl.kt | 6 +++--- .../kotlin/net.mamoe.mirai/contact/ContactList.kt | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt index cd874bae5..ec0e34c10 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt @@ -259,16 +259,16 @@ internal class GroupImpl( override operator fun get(id: Long): Member { - return members.delegate.filteringGetOrNull { it.id == id } + return members.delegate.firstOrNull { it.id == id } ?: throw NoSuchElementException("member $id not found in group $uin") } override fun contains(id: Long): Boolean { - return members.delegate.filteringGetOrNull { it.id == id } != null + return members.delegate.firstOrNull { it.id == id } != null } override fun getOrNull(id: Long): Member? { - return members.delegate.filteringGetOrNull { it.id == id } + return members.delegate.firstOrNull { it.id == id } } @OptIn(MiraiExperimentalAPI::class, LowLevelAPI::class) 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 61f19826c..64b7e8848 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 @@ -50,7 +50,8 @@ class ContactList(@MiraiInternalAPI val delegate: LockFreeLinkedLis return null } - override fun toString(): String = delegate.asSequence().joinToString(separator = ", ", prefix = "ContactList(", postfix = ")") + override fun toString(): String = + delegate.asSequence().joinToString(separator = ", ", prefix = "ContactList(", postfix = ")") } operator fun LockFreeLinkedList.get(id: Long): C { @@ -63,11 +64,17 @@ fun LockFreeLinkedList.getOrNull(id: Long): C? { return null } -inline fun LockFreeLinkedList.filteringGetOrNull(filter: (C) -> Boolean): C? { +inline fun LockFreeLinkedList.firstOrNull(filter: (C) -> Boolean): C? { forEach { if (filter(it)) return it } return null } +@PlannedRemoval("1.0.0") +@Deprecated("use firstOrNull", replaceWith = ReplaceWith("firstOrNull(filter)"), level = DeprecationLevel.ERROR) +inline fun LockFreeLinkedList.filteringGetOrNull(filter: (C) -> Boolean): C? { + return this.firstOrNull(filter) +} + /** * Collect all the elements into a [MutableList] then cast it as a [List]