Skip to content

Commit 8b246a0

Browse files
committed
feat(ConfigTypes.kt): add contentToString method to each config types
1 parent 5b9601e commit 8b246a0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

app/src/main/java/com/osfans/trime/util/config/ConfigTypes.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import com.charleskorn.kaml.yamlMap
1010
import com.charleskorn.kaml.yamlScalar
1111

1212
/** Config item base class */
13-
open class ConfigItem(val node: YamlNode) {
13+
abstract class ConfigItem(val node: YamlNode) {
1414
enum class ValueType {
1515
Null, Scalar, List, Map, Tagged
1616
}
@@ -23,6 +23,8 @@ open class ConfigItem(val node: YamlNode) {
2323
else -> ValueType.Null
2424
}
2525

26+
abstract fun contentToString(): String
27+
2628
val configValue: ConfigValue
2729
get() = this as? ConfigValue ?: error(this, "ConfigValue")
2830

@@ -47,6 +49,7 @@ class ConfigValue(private val scalar: YamlScalar) : ConfigItem(scalar) {
4749
fun getBool() = scalar.toBoolean()
4850

4951
override fun isEmpty() = scalar.content.isEmpty()
52+
override fun contentToString(): String = scalar.contentToString()
5053
}
5154

5255
/** The wrapper of [YamlList] */
@@ -56,6 +59,7 @@ class ConfigList(private val list: YamlList) : ConfigItem(list) {
5659
val items get() = list.items.map { convertFromYaml(it) }
5760

5861
override fun isEmpty() = list.items.isEmpty()
62+
override fun contentToString(): String = list.contentToString()
5963

6064
operator fun get(index: Int) = items[index]
6165
fun getValue(index: Int) = get(index)?.configValue
@@ -65,6 +69,7 @@ class ConfigMap(private val map: YamlMap) : ConfigItem(map) {
6569
constructor(item: ConfigItem) : this(item.node.yamlMap)
6670

6771
override fun isEmpty() = map.entries.isEmpty()
72+
override fun contentToString(): String = map.contentToString()
6873

6974
fun hasKey(key: String) = map.getKey(key) != null
7075

0 commit comments

Comments
 (0)