de.lancom.openapi.tools.MergeMap.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openapi-parser Show documentation
Show all versions of openapi-parser Show documentation
This open-source project provides an OpenAPI 3.0 Parser implemented in Kotlin, utilizing immutable data classes
package de.lancom.openapi.tools
import de.lancom.openapi.entity.Entity
fun mergeMap(left: Map, right: Map): Map {
val allKeys = left.keys + right.keys
return allKeys.associateWith { key ->
val l = left[key]
val r = right[key]
when {
l != null && r != null ->
if (l is Entity && r is Entity) {
@Suppress("UNCHECKED_CAST")
l.mergeEntity(r) as V
} else {
r
}
l != null ->
l
r != null ->
r
else ->
TODO("Both values should not be null")
}
}
}