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:
@@ -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 },
|
||||
|
||||
@@ -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)"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user