Commit f459891c authored by Him188moe's avatar Him188moe

Kotlin coroutine

parent 2d366d49
...@@ -104,6 +104,12 @@ abstract class Message { ...@@ -104,6 +104,12 @@ abstract class Message {
* @return message connected * @return message connected
*/ */
open fun concat(tail: Message): MessageChain { open fun concat(tail: Message): MessageChain {
if (tail is MessageChain) {
return MessageChain(this).let {
tail.list.forEach { child -> it.concat(child) }
it
}
}
return MessageChain(this, Objects.requireNonNull(tail)) return MessageChain(this, Objects.requireNonNull(tail))
} }
......
...@@ -11,6 +11,9 @@ import java.util.stream.Stream ...@@ -11,6 +11,9 @@ import java.util.stream.Stream
class MessageChain : Message { class MessageChain : Message {
override val type: Int = MessageId.CHAIN override val type: Int = MessageId.CHAIN
/**
* Elements will not be instances of [MessageChain]
*/
val list: MutableList<Message> = Collections.synchronizedList(LinkedList<Message>()) val list: MutableList<Message> = Collections.synchronizedList(LinkedList<Message>())
constructor(head: Message, tail: Message) { constructor(head: Message, tail: Message) {
...@@ -58,6 +61,10 @@ class MessageChain : Message { ...@@ -58,6 +61,10 @@ class MessageChain : Message {
} }
override fun concat(tail: Message): MessageChain { override fun concat(tail: Message): MessageChain {
if (tail is MessageChain) {
tail.list.forEach { child -> this.concat(child) }
return this
}
this.list.add(tail) this.list.add(tail)
clearToStringCache() clearToStringCache()
return this return this
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment