This commit is contained in:
Him188 2020-04-04 13:54:11 +08:00
parent 220e6d42f5
commit e8b0c99006
2 changed files with 12 additions and 5 deletions

View File

@ -259,16 +259,16 @@ internal class GroupImpl(
override operator fun get(id: Long): Member { 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") ?: throw NoSuchElementException("member $id not found in group $uin")
} }
override fun contains(id: Long): Boolean { 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? { 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) @OptIn(MiraiExperimentalAPI::class, LowLevelAPI::class)

View File

@ -50,7 +50,8 @@ class ContactList<C : Contact>(@MiraiInternalAPI val delegate: LockFreeLinkedLis
return null 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 <C : Contact> LockFreeLinkedList<C>.get(id: Long): C { operator fun <C : Contact> LockFreeLinkedList<C>.get(id: Long): C {
@ -63,11 +64,17 @@ fun <C : Contact> LockFreeLinkedList<C>.getOrNull(id: Long): C? {
return null return null
} }
inline fun <C : Contact> LockFreeLinkedList<C>.filteringGetOrNull(filter: (C) -> Boolean): C? { inline fun <C : Contact> LockFreeLinkedList<C>.firstOrNull(filter: (C) -> Boolean): C? {
forEach { if (filter(it)) return it } forEach { if (filter(it)) return it }
return null return null
} }
@PlannedRemoval("1.0.0")
@Deprecated("use firstOrNull", replaceWith = ReplaceWith("firstOrNull(filter)"), level = DeprecationLevel.ERROR)
inline fun <C : Contact> LockFreeLinkedList<C>.filteringGetOrNull(filter: (C) -> Boolean): C? {
return this.firstOrNull(filter)
}
/** /**
* Collect all the elements into a [MutableList] then cast it as a [List] * Collect all the elements into a [MutableList] then cast it as a [List]