Update docs

This commit is contained in:
Him188 2021-01-08 11:24:23 +08:00
parent 8abbfbe4c5
commit 179746c5f7
2 changed files with 18 additions and 2 deletions

View File

@ -12,11 +12,12 @@
package net.mamoe.mirai.contact package net.mamoe.mirai.contact
import net.mamoe.mirai.utils.MiraiInternalApi import net.mamoe.mirai.utils.MiraiInternalApi
import net.mamoe.mirai.utils.PlannedRemoval
import java.util.concurrent.ConcurrentLinkedQueue import java.util.concurrent.ConcurrentLinkedQueue
/** /**
* 只读联系人列表, 无锁链表实现 * 只读联系人列表. 元素列表仍可能会被 mirai 内部修改.
* *
* @see ContactList.asSequence * @see ContactList.asSequence
*/ */
@ -27,9 +28,24 @@ internal constructor(@JvmField @MiraiInternalApi public val delegate: Concurrent
internal constructor(collection: Collection<C>) : this(ConcurrentLinkedQueue(collection)) internal constructor(collection: Collection<C>) : this(ConcurrentLinkedQueue(collection))
internal constructor() : this(ConcurrentLinkedQueue()) internal constructor() : this(ConcurrentLinkedQueue())
/**
* 获取一个 [Contact.id] [id] 的元素. 在不存在时返回 `null`.
*/
public operator fun get(id: Long): C? = delegate.firstOrNull { it.id == id } public operator fun get(id: Long): C? = delegate.firstOrNull { it.id == id }
/**
* 获取一个 [Contact.id] [id] 的元素. 在不存在时抛出 [NoSuchElementException].
*/
public fun getOrFail(id: Long): C = get(id) ?: throw NoSuchElementException("Contact $id not found.") public fun getOrFail(id: Long): C = get(id) ?: throw NoSuchElementException("Contact $id not found.")
/**
* 删除 [Contact.id] [id] 的元素.
*/
public fun remove(id: Long): Boolean = delegate.removeAll { it.id == id } public fun remove(id: Long): Boolean = delegate.removeAll { it.id == id }
/**
* 当存在 [Contact.id] [id] 的元素时返回 `true`.
*/
public operator fun contains(id: Long): Boolean = get(id) != null public operator fun contains(id: Long): Boolean = get(id) != null
override fun toString(): String = delegate.joinToString(separator = ", ", prefix = "ContactList(", postfix = ")") override fun toString(): String = delegate.joinToString(separator = ", ", prefix = "ContactList(", postfix = ")")

View File

@ -68,7 +68,7 @@ import kotlin.internal.LowPriorityInOverloadResolution
* *
* @see Contact.sendMessage 发送消息 * @see Contact.sendMessage 发送消息
*/ */
public interface Message { // must be interface. Don't consider any changes. public interface Message {
/** /**
* `this` [tail] 连接. * `this` [tail] 连接.