@@ -74,40 +74,66 @@ class ConfigValue(private val scalar: YamlScalar) : ConfigItem(scalar) {
74
74
}
75
75
76
76
/* * The wrapper of [YamlList] */
77
- class ConfigList (private val list : YamlList ) : ConfigItem(list) {
77
+ class ConfigList (private val list : YamlList ) : ConfigItem(list), List<ConfigItem?> {
78
78
constructor (item: ConfigItem ) : this (item.node.yamlList)
79
79
80
- val items get() = list.items.map { convertFromYaml(it) }
80
+ private val items = list.items.map { convertFromYaml(it) }
81
81
82
- operator fun iterator () = items.iterator()
82
+ override val size = list.items.size
83
+
84
+ override fun containsAll (elements : Collection <ConfigItem ?>): Boolean = items.containsAll(elements)
85
+
86
+ override fun contains (element : ConfigItem ? ): Boolean = items.contains(element)
87
+
88
+ override operator fun iterator () = items.iterator()
89
+
90
+ override fun listIterator (): ListIterator <ConfigItem ?> = items.listIterator()
91
+
92
+ override fun listIterator (index : Int ): ListIterator <ConfigItem ?> = items.listIterator(index)
93
+
94
+ override fun subList (
95
+ fromIndex : Int ,
96
+ toIndex : Int ,
97
+ ): List <ConfigItem ?> = items.subList(fromIndex, toIndex)
98
+
99
+ override fun lastIndexOf (element : ConfigItem ? ): Int = items.lastIndexOf(element)
83
100
84
101
override fun isEmpty () = list.items.isEmpty()
85
102
86
103
override fun contentToString (): String = list.contentToString()
87
104
88
- operator fun get (index : Int ) = items[index]
105
+ override operator fun get (index : Int ): ConfigItem ? = items[index]
106
+
107
+ override fun indexOf (element : ConfigItem ? ): Int = items.indexOf(element)
89
108
90
109
fun getValue (index : Int ) = get(index)?.configValue
91
110
}
92
111
93
- class ConfigMap (private val map : YamlMap ) : ConfigItem(map) {
112
+ class ConfigMap (private val map : YamlMap ) : ConfigItem(map), Map<String, ConfigItem?> {
94
113
constructor (item: ConfigItem ) : this (item.node.yamlMap)
95
114
96
115
override fun isEmpty () = map.entries.isEmpty()
97
116
117
+ override val size: Int = map.entries.size
118
+
98
119
override fun contentToString (): String = map.contentToString()
99
120
100
- fun containsKey (key : String ) = map.getKey(key) != null
121
+ override fun containsKey (key : String ) = map.getKey(key) != null
122
+
123
+ override fun containsValue (value : ConfigItem ? ): Boolean = entries.any { it.value == value }
101
124
102
- val entries get() =
125
+ override val entries: Set < Map . Entry < String , ConfigItem ?>> =
103
126
map.entries.entries.associate { (s, n) ->
104
127
s.content to convertFromYaml(n)
105
- }
128
+ }.entries
129
+
130
+ override val keys: Set <String > = entries.map { it.key }.toSet()
131
+
132
+ override val values: Collection <ConfigItem ?> = entries.map { it.value }
106
133
107
134
operator fun iterator () = entries.iterator()
108
135
109
- @Suppress(" UNCHECKED_CAST" )
110
- operator fun <T : ConfigItem > get (key : String ): T ? = entries.entries.firstOrNull { it.key == key }?.value as T ?
136
+ override operator fun get (key : String ): ConfigItem ? = entries.firstOrNull { it.key == key }?.value
111
137
112
- fun getValue (key : String ): ConfigValue ? = get< ConfigValue > (key)?.configValue
138
+ fun getValue (key : String ): ConfigValue ? = get(key)?.configValue
113
139
}
0 commit comments