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,12 +32,16 @@ object JsonMetaFormat : MetaFormat {
}
fun Value.toJson(): JsonElement {
return when (type) {
return if(isList()){
JsonArray(list.map { it.toJson() })
} else {
when (type) {
ValueType.NUMBER -> JsonPrimitive(number)
ValueType.STRING -> JsonPrimitive(string)
ValueType.BOOLEAN -> JsonPrimitive(boolean)
ValueType.NULL -> JsonNull
}
}
}
fun Meta.toJson(): JsonObject {

View File

@ -26,6 +26,7 @@ class MetaFormatTest {
"node" to {
"b" to "DDD"
"c" to 11.1
"array" to doubleArrayOf(1.0,2.0,3.0)
}
}
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 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()
}
}
/**