From bc1efa3c2c558474c2a4d2f183284dc4c4d635ad Mon Sep 17 00:00:00 2001 From: Maximilian Irro Date: Mon, 3 May 2021 22:22:40 +0200 Subject: [PATCH] Fix parameter logic, getting rid of the try-catch bailed to early --- .../ValidatingGeographicLocationBuilder.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/dev/stalla/builder/validating/ValidatingGeographicLocationBuilder.kt b/src/main/kotlin/dev/stalla/builder/validating/ValidatingGeographicLocationBuilder.kt index 4bb537bd..1efd7b15 100644 --- a/src/main/kotlin/dev/stalla/builder/validating/ValidatingGeographicLocationBuilder.kt +++ b/src/main/kotlin/dev/stalla/builder/validating/ValidatingGeographicLocationBuilder.kt @@ -5,6 +5,7 @@ import dev.stalla.model.podcastindex.GeographicLocation import dev.stalla.model.podcastindex.GeographicLocation.Factory.CRS_PARAM import dev.stalla.model.podcastindex.GeographicLocation.Factory.UNCERTAINTY_PARAM import dev.stalla.util.InternalAPI +import java.util.Locale @InternalAPI internal class ValidatingGeographicLocationBuilder : GeographicLocationBuilder { @@ -27,15 +28,18 @@ internal class ValidatingGeographicLocationBuilder : GeographicLocationBuilder { override fun uncertainty(uncertainty: Double?): GeographicLocationBuilder = apply { this.uncertainty = uncertainty } override fun addParameter(key: String, value: String): GeographicLocationBuilder = apply { - if (CRS_PARAM.equals(key, ignoreCase = true)) { - crs(value) - return@apply + when (key.toLowerCase(Locale.ROOT)) { + CRS_PARAM -> crs(value) + UNCERTAINTY_PARAM -> { + val uncertaintyValue = value.toDoubleOrNull() + if (uncertaintyValue != null) { + uncertainty(uncertaintyValue) + } else { + parameters[key] = value + } + } + else -> parameters[key] = value } - if (UNCERTAINTY_PARAM.equals(key, ignoreCase = true)) { - val uncertaintyValue = value.toDoubleOrNull() ?: return@apply - uncertainty(uncertaintyValue) - } - parameters[key] = value } override fun removeParameter(key: String): GeographicLocationBuilder = apply {