From 46a23d17d5daf05b4b3e41a47bb870e54de968b3 Mon Sep 17 00:00:00 2001 From: dankl Date: Sun, 6 Oct 2019 14:30:00 +0200 Subject: [PATCH] Extracted parseCodeEnum() for a single value --- .../net/dankito/fints/response/ResponseParser.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/ResponseParser.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/ResponseParser.kt index 1bdd3534..dc805f8f 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/ResponseParser.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/ResponseParser.kt @@ -135,7 +135,7 @@ open class ResponseParser { val iban = returnNullIfEmpty(dataElementGroups[2]) val customerId = dataElementGroups[3] - val accountType = parseCodeEnum(listOf(dataElementGroups[4]), AccountTypeCode.values()).first().type + val accountType = parseCodeEnum(dataElementGroups[4], AccountTypeCode.values()).type val currency = dataElementGroups[5] val accountHolderName1 = dataElementGroups[6] val accountHolderName2 = returnNullIfEmpty(dataElementGroups[7]) @@ -181,7 +181,7 @@ open class ResponseParser { } protected open fun parseSecurityMethod(methodString: String): Sicherheitsverfahren { - return parseCodeEnum(listOf(methodString), Sicherheitsverfahren.values()).first() + return parseCodeEnum(methodString, Sicherheitsverfahren.values()) } protected open fun parseSecurityMethodVersion(versionString: String): VersionDesSicherheitsverfahrens { @@ -192,7 +192,11 @@ open class ResponseParser { protected open fun parseCodeEnum(codeValues: List, allValues: Array): List { // mapNotNull: don't crash if new, at time of implementation unknown values get introduced / returned by bank - return codeValues.mapNotNull { code -> allValues.first { it.code == code } } + return codeValues.mapNotNull { code -> parseCodeEnum(code, allValues) } + } + + protected open fun parseCodeEnum(code: String, allValues: Array): T { + return allValues.first { it.code == code } }