Fixed JsonMetaForat and ListValue equality
This commit is contained in:
parent
60ab98dde6
commit
da2c59fdfe
@ -32,11 +32,15 @@ object JsonMetaFormat : MetaFormat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Value.toJson(): JsonElement {
|
fun Value.toJson(): JsonElement {
|
||||||
return when (type) {
|
return if(isList()){
|
||||||
ValueType.NUMBER -> JsonPrimitive(number)
|
JsonArray(list.map { it.toJson() })
|
||||||
ValueType.STRING -> JsonPrimitive(string)
|
} else {
|
||||||
ValueType.BOOLEAN -> JsonPrimitive(boolean)
|
when (type) {
|
||||||
ValueType.NULL -> JsonNull
|
ValueType.NUMBER -> JsonPrimitive(number)
|
||||||
|
ValueType.STRING -> JsonPrimitive(string)
|
||||||
|
ValueType.BOOLEAN -> JsonPrimitive(boolean)
|
||||||
|
ValueType.NULL -> JsonNull
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ class MetaFormatTest {
|
|||||||
"node" to {
|
"node" to {
|
||||||
"b" to "DDD"
|
"b" to "DDD"
|
||||||
"c" to 11.1
|
"c" to 11.1
|
||||||
|
"array" to doubleArrayOf(1.0,2.0,3.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val string = meta.asString(JsonMetaFormat)
|
val string = meta.asString(JsonMetaFormat)
|
||||||
|
@ -178,6 +178,22 @@ class ListValue(override val list: List<Value>) : Value {
|
|||||||
override val string: String get() = list.first().string
|
override val string: String get() = list.first().string
|
||||||
|
|
||||||
override fun toString(): String = value.toString()
|
override fun toString(): String = value.toString()
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (other !is Value) return false
|
||||||
|
val otherList = other.list
|
||||||
|
if (list.size != otherList.size) return false
|
||||||
|
|
||||||
|
|
||||||
|
return (0 until list.size).all { list[it] == otherList[it] }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return list.hashCode()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user