-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix lists serialization and factorise ObjsectsUtils
- Loading branch information
Showing
15 changed files
with
135 additions
and
74 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
serialize-core/src/commonMain/kotlin/it/unibo/tuprolog/serialize/ObjectsUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package it.unibo.tuprolog.serialize | ||
|
||
expect object ObjectsUtils { | ||
fun parseAsObject(string: String, mimeType: MimeType): Any | ||
|
||
fun deeplyEqual(obj1: Any?, obj2: Any?): Boolean | ||
} |
5 changes: 0 additions & 5 deletions
5
serialize-core/src/commonTest/kotlin/it/unibo/tuprolog/serialize/Parsing.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
serialize-core/src/jsMain/kotlin/it/unibo/tuprolog/serialize/ObjectsUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package it.unibo.tuprolog.serialize | ||
|
||
actual object ObjectsUtils { | ||
|
||
actual fun parseAsObject(string: String, mimeType: MimeType): Any { | ||
return when (mimeType) { | ||
is MimeType.Xml -> throw NotImplementedError() | ||
is MimeType.Yaml -> YAML.parse(string) | ||
is MimeType.Json -> JSON.parse(string) | ||
} as Any | ||
} | ||
|
||
actual fun deeplyEqual(obj1: Any?, obj2: Any?): Boolean { | ||
return JSON.stringify(obj1) == JSON.stringify(obj2) | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
serialize-core/src/jsTest/kotlin/it/unibo/tuprolog/serialize/Parsing.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
serialize-core/src/jvmMain/kotlin/it/unibo/tuprolog/serialize/ObjectsUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package it.unibo.tuprolog.serialize | ||
|
||
actual object ObjectsUtils { | ||
actual fun parseAsObject(string: String, mimeType: MimeType): Any { | ||
return mimeType.objectMapper.readValue(string, java.lang.Object::class.java) | ||
} | ||
|
||
actual fun deeplyEqual(obj1: Any?, obj2: Any?): Boolean { | ||
return when { | ||
obj1 is Number && obj2 is Number -> obj1.toString() == obj2.toString() | ||
obj1 is List<*> && obj2 is List<*> -> obj1.asSequence().zip(obj2.asSequence()).all { | ||
deeplyEqual(it.first, it.second) | ||
} | ||
obj1 is Map<*,*> && obj2 is Map<*,*> -> { | ||
if (obj1.keys != obj2.keys) { | ||
false | ||
} else { | ||
obj1.keys.all { deeplyEqual(obj1[it], obj2[it]) } | ||
} | ||
} | ||
else -> obj1 == obj2 | ||
} | ||
} | ||
} |
22 changes: 0 additions & 22 deletions
22
serialize-core/src/jvmTest/kotlin/it/unibo/tuprolog/serialize/Parsing.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters