Refactor code (rename allTypes matcher to anyType) and create unwrap*() methods which converts wrapped with Value values to raw Kotlin's objects

This commit is contained in:
2020-03-14 14:10:31 +01:00
parent 5b03f55cd4
commit d3f6138a8b
8 changed files with 60 additions and 54 deletions

View File

@@ -104,7 +104,7 @@ class Matcher(val type: DataType?, private val matcher: (Value) -> Boolean, priv
)
}
fun allTypes(): Matcher {
fun anyType(): Matcher {
return Matcher(
null,
{ it.type != DataType.VOID },

View File

@@ -16,6 +16,22 @@ data class Value(val type: DataType, val value: Any, val properties: Map<String,
val typeName: String
get() = type.toString()
fun unwrapCollections(): Any {
return when(type) {
DataType.LIST -> (value as List<Value>).map { it.unwrapCollections() }
DataType.MAP -> (value as Map<Value, Value>).map { (k, v) -> k.unwrapCollections() to v.unwrapCollections() }.toMap()
else -> this
}
}
fun unwrap(): Any {
return when(type) {
DataType.LIST -> (value as List<Value>).map { it.unwrap() }
DataType.MAP -> (value as Map<Value, Value>).map { (k, v) -> k.unwrap() to v.unwrap() }.toMap()
else -> value
}
}
override fun toString(): String {
return "$type($value)"
}