|
|
@@ -11,8 +11,9 @@
|
|
|
|
|
|
package net.mamoe.mirai.contact
|
|
|
|
|
|
-import net.mamoe.mirai.utils.*
|
|
|
-import kotlin.jvm.JvmName
|
|
|
+import net.mamoe.mirai.utils.LockFreeLinkedList
|
|
|
+import net.mamoe.mirai.utils.asSequence
|
|
|
+import kotlin.jvm.JvmField
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -20,9 +21,8 @@ import kotlin.jvm.JvmName
|
|
|
*
|
|
|
* @see ContactList.asSequence
|
|
|
*/
|
|
|
-@OptIn(MiraiInternalAPI::class)
|
|
|
@Suppress("unused")
|
|
|
-class ContactList<C : Contact>(@MiraiInternalAPI("Implementation may change in future release") val delegate: LockFreeLinkedList<C>) :
|
|
|
+class ContactList<C : Contact> internal constructor(@JvmField internal val delegate: LockFreeLinkedList<C>) :
|
|
|
Iterable<C> {
|
|
|
operator fun get(id: Long): C =
|
|
|
delegate.asSequence().firstOrNull { it.id == id } ?: throw NoSuchElementException("Contact id $id")
|
|
|
@@ -41,31 +41,6 @@ class ContactList<C : Contact>(@MiraiInternalAPI("Implementation may change in f
|
|
|
override fun iterator(): Iterator<C> {
|
|
|
return this.delegate.asSequence().iterator()
|
|
|
}
|
|
|
-
|
|
|
- @PlannedRemoval("1.0.0")
|
|
|
- @Suppress("PropertyName")
|
|
|
- @get:JvmName("getIdContentString")
|
|
|
- @Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
|
- val _idContentString: String
|
|
|
- get() = this.idContentString
|
|
|
-
|
|
|
- @PlannedRemoval("1.0.0")
|
|
|
- @Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
|
- inline fun forEach(block: (C) -> Unit) = delegate.forEach(block)
|
|
|
-
|
|
|
- @PlannedRemoval("1.0.0")
|
|
|
- @Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
|
- fun first(): C {
|
|
|
- forEach { return it }
|
|
|
- throw NoSuchElementException()
|
|
|
- }
|
|
|
-
|
|
|
- @PlannedRemoval("1.0.0")
|
|
|
- @Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
|
- fun firstOrNull(): C? {
|
|
|
- forEach { return it }
|
|
|
- return null
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -76,64 +51,17 @@ class ContactList<C : Contact>(@MiraiInternalAPI("Implementation may change in f
|
|
|
* ```
|
|
|
*/
|
|
|
val ContactList<*>.idContentString: String
|
|
|
- get() = "[" + @OptIn(MiraiInternalAPI::class) buildString { delegate.forEach { append(it.id).append(", ") } }.dropLast(
|
|
|
+ get() = "[" + buildString { delegate.forEach { append(it.id).append(", ") } }.dropLast(
|
|
|
2
|
|
|
) + "]"
|
|
|
|
|
|
|
|
|
-@MiraiInternalAPI
|
|
|
-operator fun <C : Contact> LockFreeLinkedList<C>.get(id: Long): C {
|
|
|
+internal operator fun <C : Contact> LockFreeLinkedList<C>.get(id: Long): C {
|
|
|
forEach { if (it.id == id) return it }
|
|
|
throw NoSuchElementException("No such contact: $id")
|
|
|
}
|
|
|
|
|
|
-@MiraiInternalAPI
|
|
|
-fun <C : Contact> LockFreeLinkedList<C>.getOrNull(id: Long): C? {
|
|
|
+internal fun <C : Contact> LockFreeLinkedList<C>.getOrNull(id: Long): C? {
|
|
|
forEach { if (it.id == id) return it }
|
|
|
return null
|
|
|
-}
|
|
|
-
|
|
|
-@OptIn(MiraiInternalAPI::class)
|
|
|
-@PlannedRemoval("1.0.0")
|
|
|
-@Deprecated(
|
|
|
- "use firstOrNull from stdlib",
|
|
|
- replaceWith = ReplaceWith("this.asSequence().firstOrNull(filter)"),
|
|
|
- level = DeprecationLevel.ERROR
|
|
|
-)
|
|
|
-inline fun <C : Contact> LockFreeLinkedList<C>.firstOrNull(filter: (C) -> Boolean): C? {
|
|
|
- forEach { if (filter(it)) return it }
|
|
|
- return null
|
|
|
-}
|
|
|
-
|
|
|
-@OptIn(MiraiInternalAPI::class)
|
|
|
-@PlannedRemoval("1.0.0")
|
|
|
-@Deprecated(
|
|
|
- "use firstOrNull from stdlib",
|
|
|
- replaceWith = ReplaceWith("firstOrNull(filter)"),
|
|
|
- level = DeprecationLevel.ERROR
|
|
|
-)
|
|
|
-inline fun <C : Contact> LockFreeLinkedList<C>.filteringGetOrNull(filter: (C) -> Boolean): C? =
|
|
|
- this.asSequence().firstOrNull(filter)
|
|
|
-
|
|
|
-@PlannedRemoval("1.0.0")
|
|
|
-@Deprecated("use Iterator.toList from stdlib", level = DeprecationLevel.HIDDEN)
|
|
|
-fun <E : Contact> ContactList<E>.toList(): List<E> = toMutableList()
|
|
|
-
|
|
|
-@PlannedRemoval("1.0.0")
|
|
|
-@Deprecated("use Iterator.toMutableList from stdlib", level = DeprecationLevel.HIDDEN)
|
|
|
-@OptIn(MiraiInternalAPI::class)
|
|
|
-fun <E : Contact> ContactList<E>.toMutableList(): MutableList<E> = this.delegate.toMutableList()
|
|
|
-
|
|
|
-@PlannedRemoval("1.0.0")
|
|
|
-@Deprecated("use Iterator.toSet from stdlib", level = DeprecationLevel.HIDDEN)
|
|
|
-fun <E : Contact> ContactList<E>.toSet(): Set<E> = toMutableSet()
|
|
|
-
|
|
|
-@PlannedRemoval("1.0.0")
|
|
|
-@Deprecated("use Iterator.toMutableSet from stdlib", level = DeprecationLevel.HIDDEN)
|
|
|
-@OptIn(MiraiInternalAPI::class)
|
|
|
-fun <E : Contact> ContactList<E>.toMutableSet(): MutableSet<E> = this.delegate.toMutableSet()
|
|
|
-
|
|
|
-@PlannedRemoval("1.0.0")
|
|
|
-@Deprecated("use Iterator.asSequence from stdlib", level = DeprecationLevel.HIDDEN)
|
|
|
-@OptIn(MiraiInternalAPI::class)
|
|
|
-fun <E : Contact> ContactList<E>.asSequence(): Sequence<E> = this.delegate.asSequence()
|
|
|
+}
|