Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
f6095763
Commit
f6095763
authored
Dec 14, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract ContactList to a new file
parent
4a2bdba0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
48 deletions
+56
-48
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt
.../src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt
+0
-48
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/ContactList.kt
.../commonMain/kotlin/net.mamoe.mirai/contact/ContactList.kt
+56
-0
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt
View file @
f6095763
...
...
@@ -56,51 +56,3 @@ inline fun <R> Contact.withSession(block: BotSession.() -> R): R {
}
return
bot
.
withSession
(
block
)
}
/**
* 只读联系人列表, lock-free 实现
*/
@UseExperimental
(
MiraiInternalAPI
::
class
)
@Suppress
(
"unused"
)
class
ContactList
<
C
:
Contact
>(
@PublishedApi
internal
val
delegate
:
MutableContactList
<
C
>)
{
/**
* ID 列表的字符串表示.
* 如:
* ```
* [123456, 321654, 123654]
* ```
*/
val
idContentString
:
String
get
()
=
"["
+
buildString
{
delegate
.
forEach
{
append
(
it
.
id
).
append
(
", "
)
}
}.
dropLast
(
2
)
+
"]"
operator
fun
get
(
id
:
UInt
):
C
=
delegate
[
id
]
fun
getOrNull
(
id
:
UInt
):
C
?
=
delegate
.
getOrNull
(
id
)
fun
containsId
(
id
:
UInt
):
Boolean
=
delegate
.
getOrNull
(
id
)
!=
null
val
size
:
Int
get
()
=
delegate
.
size
operator
fun
contains
(
element
:
C
):
Boolean
=
delegate
.
contains
(
element
)
fun
containsAll
(
elements
:
Collection
<
C
>):
Boolean
=
elements
.
all
{
contains
(
it
)
}
fun
isEmpty
():
Boolean
=
delegate
.
isEmpty
()
inline
fun
forEach
(
block
:
(
C
)
->
Unit
)
=
delegate
.
forEach
(
block
)
override
fun
toString
():
String
=
delegate
.
joinToString
(
separator
=
", "
,
prefix
=
"ContactList("
,
postfix
=
")"
)
}
/**
* 可修改联系人列表. 只会在内部使用.
*/
@MiraiInternalAPI
class
MutableContactList
<
C
:
Contact
>
:
LockFreeLinkedList
<
C
>()
{
override
fun
toString
():
String
=
joinToString
(
separator
=
", "
,
prefix
=
"MutableContactList("
,
postfix
=
")"
)
operator
fun
get
(
id
:
UInt
):
C
{
forEach
{
if
(
it
.
id
==
id
)
return
it
}
throw
NoSuchElementException
()
}
fun
getOrNull
(
id
:
UInt
):
C
?
{
forEach
{
if
(
it
.
id
==
id
)
return
it
}
return
null
}
fun
getOrAdd
(
id
:
UInt
,
supplier
:
()
->
C
):
C
=
super
.
filteringGetOrAdd
({
it
.
id
==
id
},
supplier
)
}
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/ContactList.kt
0 → 100644
View file @
f6095763
@
file
:
Suppress
(
"EXPERIMENTAL_API_USAGE"
)
package
net.mamoe.mirai.contact
import
net.mamoe.mirai.utils.LockFreeLinkedList
import
net.mamoe.mirai.utils.MiraiInternalAPI
import
net.mamoe.mirai.utils.joinToString
/**
* 只读联系人列表, lock-free 实现
*/
@UseExperimental
(
MiraiInternalAPI
::
class
)
@Suppress
(
"unused"
)
class
ContactList
<
C
:
Contact
>(
@PublishedApi
internal
val
delegate
:
MutableContactList
<
C
>)
{
/**
* ID 列表的字符串表示.
* 如:
* ```
* [123456, 321654, 123654]
* ```
*/
val
idContentString
:
String
get
()
=
"["
+
buildString
{
delegate
.
forEach
{
append
(
it
.
id
).
append
(
", "
)
}
}.
dropLast
(
2
)
+
"]"
operator
fun
get
(
id
:
UInt
):
C
=
delegate
[
id
]
fun
getOrNull
(
id
:
UInt
):
C
?
=
delegate
.
getOrNull
(
id
)
fun
containsId
(
id
:
UInt
):
Boolean
=
delegate
.
getOrNull
(
id
)
!=
null
val
size
:
Int
get
()
=
delegate
.
size
operator
fun
contains
(
element
:
C
):
Boolean
=
delegate
.
contains
(
element
)
fun
containsAll
(
elements
:
Collection
<
C
>):
Boolean
=
elements
.
all
{
contains
(
it
)
}
fun
isEmpty
():
Boolean
=
delegate
.
isEmpty
()
inline
fun
forEach
(
block
:
(
C
)
->
Unit
)
=
delegate
.
forEach
(
block
)
override
fun
toString
():
String
=
delegate
.
joinToString
(
separator
=
", "
,
prefix
=
"ContactList("
,
postfix
=
")"
)
}
/**
* 可修改联系人列表. 只会在内部使用.
*/
@MiraiInternalAPI
class
MutableContactList
<
C
:
Contact
>
:
LockFreeLinkedList
<
C
>()
{
override
fun
toString
():
String
=
joinToString
(
separator
=
", "
,
prefix
=
"MutableContactList("
,
postfix
=
")"
)
operator
fun
get
(
id
:
UInt
):
C
{
forEach
{
if
(
it
.
id
==
id
)
return
it
}
throw
NoSuchElementException
()
}
fun
getOrNull
(
id
:
UInt
):
C
?
{
forEach
{
if
(
it
.
id
==
id
)
return
it
}
return
null
}
fun
getOrAdd
(
id
:
UInt
,
supplier
:
()
->
C
):
C
=
super
.
filteringGetOrAdd
({
it
.
id
==
id
},
supplier
)
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment