@@ -10,7 +10,7 @@ import com.charleskorn.kaml.yamlMap
10
10
import com.charleskorn.kaml.yamlScalar
11
11
12
12
/* * Config item base class */
13
- open class ConfigItem (val node : YamlNode ) {
13
+ abstract class ConfigItem (val node : YamlNode ) {
14
14
enum class ValueType {
15
15
Null , Scalar , List , Map , Tagged
16
16
}
@@ -23,6 +23,8 @@ open class ConfigItem(val node: YamlNode) {
23
23
else -> ValueType .Null
24
24
}
25
25
26
+ abstract fun contentToString (): String
27
+
26
28
val configValue: ConfigValue
27
29
get() = this as ? ConfigValue ? : error(this , " ConfigValue" )
28
30
@@ -47,6 +49,7 @@ class ConfigValue(private val scalar: YamlScalar) : ConfigItem(scalar) {
47
49
fun getBool () = scalar.toBoolean()
48
50
49
51
override fun isEmpty () = scalar.content.isEmpty()
52
+ override fun contentToString (): String = scalar.contentToString()
50
53
}
51
54
52
55
/* * The wrapper of [YamlList] */
@@ -56,6 +59,7 @@ class ConfigList(private val list: YamlList) : ConfigItem(list) {
56
59
val items get() = list.items.map { convertFromYaml(it) }
57
60
58
61
override fun isEmpty () = list.items.isEmpty()
62
+ override fun contentToString (): String = list.contentToString()
59
63
60
64
operator fun get (index : Int ) = items[index]
61
65
fun getValue (index : Int ) = get(index)?.configValue
@@ -65,6 +69,7 @@ class ConfigMap(private val map: YamlMap) : ConfigItem(map) {
65
69
constructor (item: ConfigItem ) : this (item.node.yamlMap)
66
70
67
71
override fun isEmpty () = map.entries.isEmpty()
72
+ override fun contentToString (): String = map.contentToString()
68
73
69
74
fun hasKey (key : String ) = map.getKey(key) != null
70
75
0 commit comments