1
1
package dev.openfeature.kotlin.sdk
2
2
3
+ import kotlinx.collections.immutable.toImmutableList
4
+ import kotlinx.collections.immutable.toImmutableMap
3
5
import kotlin.time.ExperimentalTime
4
6
5
7
class ImmutableStructure (attributes : Map <String , Value > = mapOf()) : Structure {
6
- private val attributes: Map <String , Value > = attributes.toMap ()
8
+ private val attributes: Map <String , Value > = attributes.toImmutableMap ()
7
9
8
10
constructor (vararg pairs: Pair <String , Value >) : this (pairs.toMap())
9
11
@@ -16,18 +18,18 @@ class ImmutableStructure(attributes: Map<String, Value> = mapOf()) : Structure {
16
18
}
17
19
18
20
override fun asMap (): Map <String , Value > {
19
- return attributes.toMap()
21
+ return attributes
20
22
}
21
23
22
24
override fun asObjectMap (): Map <String , Any ?> {
23
- return attributes.mapValues { convertValue(it.value) }.toMap ()
25
+ return attributes.mapValues { convertValue(it.value) }.toImmutableMap ()
24
26
}
25
27
26
28
@OptIn(ExperimentalTime ::class )
27
29
private fun convertValue (value : Value ): Any? {
28
30
return when (value) {
29
- is Value .List -> value.list.map { t -> convertValue(t) }.toList ()
30
- is Value .Structure -> value.structure.mapValues { t -> convertValue(t.value) }.toMap ()
31
+ is Value .List -> value.list.map { t -> convertValue(t) }.toImmutableList ()
32
+ is Value .Structure -> value.structure.mapValues { t -> convertValue(t.value) }.toImmutableMap ()
31
33
is Value .Null -> return null
32
34
is Value .String -> value.asString()
33
35
is Value .Boolean -> value.asBoolean()
0 commit comments