Fixed JsonMetaForat and ListValue equality
This commit is contained in:
parent
60ab98dde6
commit
da2c59fdfe
@ -32,13 +32,17 @@ object JsonMetaFormat : MetaFormat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Value.toJson(): JsonElement {
|
fun Value.toJson(): JsonElement {
|
||||||
return when (type) {
|
return if(isList()){
|
||||||
|
JsonArray(list.map { it.toJson() })
|
||||||
|
} else {
|
||||||
|
when (type) {
|
||||||
ValueType.NUMBER -> JsonPrimitive(number)
|
ValueType.NUMBER -> JsonPrimitive(number)
|
||||||
ValueType.STRING -> JsonPrimitive(string)
|
ValueType.STRING -> JsonPrimitive(string)
|
||||||
ValueType.BOOLEAN -> JsonPrimitive(boolean)
|
ValueType.BOOLEAN -> JsonPrimitive(boolean)
|
||||||
ValueType.NULL -> JsonNull
|
ValueType.NULL -> JsonNull
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun Meta.toJson(): JsonObject {
|
fun Meta.toJson(): JsonObject {
|
||||||
val map = this.items.mapValues { entry ->
|
val map = this.items.mapValues { entry ->
|
||||||
|
@ -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