Fixed JsonMetaForat and ListValue equality

This commit is contained in:
Alexander Nozik 2019-04-30 21:04:55 +03:00
parent 60ab98dde6
commit da2c59fdfe
3 changed files with 26 additions and 5 deletions

View File

@ -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
}
} }
} }

View File

@ -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)

View File

@ -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()
}
} }
/** /**