@@ -5,30 +5,34 @@ import dev.yorkie.document.time.ActorID
5
5
public typealias P = Map <String , String >
6
6
7
7
public class Presences private constructor(
8
- private val map : MutableMap <ActorID , MutableMap <String , String >>,
8
+ private val map : Map <ActorID , Map <String , String >>,
9
9
) : Map<ActorID, P> by map {
10
10
11
- internal constructor () : this (mutableMapOf ())
12
-
13
11
public operator fun plus (presenceInfo : Pair <ActorID , P >): Presences {
14
12
val (actorID, presence) = presenceInfo
15
13
val newPresence = map[actorID].orEmpty() + presence
16
- return (map + (actorID to newPresence)).asPresences( )
14
+ return Presences (map + (actorID to newPresence))
17
15
}
18
16
19
- public operator fun minus (actorID : ActorID ): Presences = (map - actorID).asPresences()
17
+ public operator fun minus (actorID : ActorID ): Presences {
18
+ return Presences (map - actorID)
19
+ }
20
20
21
21
override fun toString (): String {
22
22
return map.entries.toString()
23
23
}
24
24
25
25
companion object {
26
26
public fun Map <ActorID , P >.asPresences (): Presences {
27
- return Presences (mapValues { it.value.toMutableMap() }.toMutableMap())
27
+ return if (this is Presences ) {
28
+ Presences (map)
29
+ } else {
30
+ Presences (this )
31
+ }
28
32
}
29
33
30
34
public fun Pair <ActorID , P >.asPresences (): Presences {
31
- return Presences (mutableMapOf (first to second.toMutableMap() ))
35
+ return Presences (mapOf ( this ))
32
36
}
33
37
34
38
internal val UninitializedPresences = Presences (
0 commit comments