diff options
author | Robert Jaros <rjaros@finn.pl> | 2018-08-16 10:23:14 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2018-08-16 10:23:14 +0200 |
commit | d47ea849d13634e4df079dca6caf3697015c51bd (patch) | |
tree | 0ecc48c9d2e0a3d1b1ef568a7d74fa102efcdead /src/main/kotlin | |
parent | eddaf3b80f887973380666d8c172ebc0cf238c69 (diff) | |
download | kvision-0.0.15.tar.gz kvision-0.0.15.tar.bz2 kvision-0.0.15.zip |
Main dependencies upgrade (Kotlin 1.2.60, coroutines 0.24.0, serialization 0.6.1, frontend plugin 0.0.37, jooby 1.5.0)0.0.15
Diffstat (limited to 'src/main/kotlin')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/form/Form.kt | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/Form.kt b/src/main/kotlin/pl/treksoft/kvision/form/Form.kt index 18acdf9f..b1e08606 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/Form.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/Form.kt @@ -42,6 +42,24 @@ internal data class FieldParams<in F : FormControl>( ) /** + * A wrapper for a Map with a custom containsKey method implementation. + * Used with kotlinx.serialization Mapper. + */ +private class FormMapWrapper<out V>(private val map: Map<String, V>) : Map<String, V> { + override fun equals(other: Any?): Boolean = map == other + override fun hashCode(): Int = map.hashCode() + override fun toString(): String = map.toString() + override val size: Int get() = map.size + override fun isEmpty(): Boolean = map.isEmpty() + override fun containsKey(key: String): Boolean = if (key.indexOf('.') != -1) map.containsKey(key) else !(map.containsKey("$key.time") || map.containsKey("$key.size")) + override fun containsValue(value: @UnsafeVariance V): Boolean = map.containsValue(value) + override fun get(key: String): V? = map[key] + override val keys: Set<String> get() = map.keys + override val values: Collection<V> get() = map.values + override val entries: Set<Map.Entry<String, V>> get() = map.entries +} + +/** * The form definition class. Can be used directly or indirectly inside a [FormPanel]. * * @constructor Creates a form with a given modelFactory function @@ -67,9 +85,9 @@ class Form<K : Any>(private val panel: FormPanel<K>? = null, private val seriali } is List<*> -> { @Suppress("UNCHECKED_CAST") - (entry.value as? List<KFile>)?.let { - listOf(entry.key to entry.value, "${entry.key}.size" to it.size) + - it.mapIndexed { index, kFile -> + (entry.value as? List<KFile>)?.let { list -> + listOf(entry.key to entry.value, "${entry.key}.size" to list.size) + + list.mapIndexed { index, kFile -> listOf( "${entry.key}.${index + 1}.name" to kFile.name, "${entry.key}.${index + 1}.size" to kFile.size, @@ -80,8 +98,8 @@ class Form<K : Any>(private val panel: FormPanel<K>? = null, private val seriali } else -> listOf(entry.key to entry.value) } - }.toMap().withDefault { null } - val mapper = Mapper.InNullableMapper(map) + }.toMap() + val mapper = Mapper.InNullableMapper(FormMapWrapper(map)) mapper.read(serializer) } } |