From f54c082af061b05ac380be5f647905b517c0589b Mon Sep 17 00:00:00 2001 From: dankl Date: Sat, 12 Oct 2019 12:37:08 +0200 Subject: [PATCH] Renamed Mt940AccountTransactionsParser to Mt940Parser and parseTransactions() to parseMt940String() --- .../mt940/IAccountTransactionsParser.kt | 10 ---------- .../fints/transactions/mt940/IMt940Parser.kt | 10 ++++++++++ ...countTransactionsParser.kt => Mt940Parser.kt} | 14 +++++++------- ...nsactionsParserTest.kt => Mt940ParserTest.kt} | 16 ++++++++-------- 4 files changed, 25 insertions(+), 25 deletions(-) delete mode 100644 fints4javaLib/src/main/kotlin/net/dankito/fints/transactions/mt940/IAccountTransactionsParser.kt create mode 100644 fints4javaLib/src/main/kotlin/net/dankito/fints/transactions/mt940/IMt940Parser.kt rename fints4javaLib/src/main/kotlin/net/dankito/fints/transactions/mt940/{Mt940AccountTransactionsParser.kt => Mt940Parser.kt} (96%) rename fints4javaLib/src/test/kotlin/net/dankito/fints/transactions/{Mt940AccountTransactionsParserTest.kt => Mt940ParserTest.kt} (93%) diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/transactions/mt940/IAccountTransactionsParser.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/transactions/mt940/IAccountTransactionsParser.kt deleted file mode 100644 index 99b8fcfa..00000000 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/transactions/mt940/IAccountTransactionsParser.kt +++ /dev/null @@ -1,10 +0,0 @@ -package net.dankito.fints.transactions.mt940 - -import net.dankito.fints.transactions.mt940.model.AccountStatement - - -interface IAccountTransactionsParser { - - fun parseTransactions(transactionsString: String): List - -} \ No newline at end of file diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/transactions/mt940/IMt940Parser.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/transactions/mt940/IMt940Parser.kt new file mode 100644 index 00000000..29e0e22b --- /dev/null +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/transactions/mt940/IMt940Parser.kt @@ -0,0 +1,10 @@ +package net.dankito.fints.transactions.mt940 + +import net.dankito.fints.transactions.mt940.model.AccountStatement + + +interface IMt940Parser { + + fun parseMt940String(mt940String: String): List + +} \ No newline at end of file diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/transactions/mt940/Mt940AccountTransactionsParser.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/transactions/mt940/Mt940Parser.kt similarity index 96% rename from fints4javaLib/src/main/kotlin/net/dankito/fints/transactions/mt940/Mt940AccountTransactionsParser.kt rename to fints4javaLib/src/main/kotlin/net/dankito/fints/transactions/mt940/Mt940Parser.kt index 4f2b2edd..0adcae1c 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/transactions/mt940/Mt940AccountTransactionsParser.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/transactions/mt940/Mt940Parser.kt @@ -21,7 +21,7 @@ user‐to‐user messages. Character ”‐” is not permitted as the first character of the line. None of lines include only Space. */ -open class Mt940AccountTransactionsParser : IAccountTransactionsParser { +open class Mt940Parser : IMt940Parser { companion object { val AccountStatementsSeparatorPattern = Pattern.compile("^\\s*-\\s*\$") // a line only with '-' and may other white space characters @@ -55,27 +55,27 @@ open class Mt940AccountTransactionsParser : IAccountTransactionsParser { val UsageTypePattern = Pattern.compile("\\w{4}\\+") - private val log = LoggerFactory.getLogger(Mt940AccountTransactionsParser::class.java) + private val log = LoggerFactory.getLogger(Mt940Parser::class.java) } - override fun parseTransactions(transactionsString: String): List { + override fun parseMt940String(mt940String: String): List { try { - val singleAccountStatementsStrings = splitIntoSingleAccountStatements(transactionsString) + val singleAccountStatementsStrings = splitIntoSingleAccountStatements(mt940String) return singleAccountStatementsStrings.mapNotNull { parseAccountStatement(it) } } catch (e: Exception) { - log.error("Could not parse account transactions from string:\n$transactionsString", e) + log.error("Could not parse account statements from MT940 string:\n$mt940String", e) } return listOf() } - protected open fun splitIntoSingleAccountStatements(transactionsString: String): List { + protected open fun splitIntoSingleAccountStatements(mt940String: String): List { val accountStatements = mutableListOf() - val lines = transactionsString.split("\n") + val lines = mt940String.split("\n") var lastMatchedLine = 0 lines.forEachIndexed { index, line -> if (line == "-") { diff --git a/fints4javaLib/src/test/kotlin/net/dankito/fints/transactions/Mt940AccountTransactionsParserTest.kt b/fints4javaLib/src/test/kotlin/net/dankito/fints/transactions/Mt940ParserTest.kt similarity index 93% rename from fints4javaLib/src/test/kotlin/net/dankito/fints/transactions/Mt940AccountTransactionsParserTest.kt rename to fints4javaLib/src/test/kotlin/net/dankito/fints/transactions/Mt940ParserTest.kt index a9af46e1..7895572f 100644 --- a/fints4javaLib/src/test/kotlin/net/dankito/fints/transactions/Mt940AccountTransactionsParserTest.kt +++ b/fints4javaLib/src/test/kotlin/net/dankito/fints/transactions/Mt940ParserTest.kt @@ -1,6 +1,6 @@ package net.dankito.fints.transactions -import net.dankito.fints.transactions.mt940.Mt940AccountTransactionsParser +import net.dankito.fints.transactions.mt940.Mt940Parser import net.dankito.fints.transactions.mt940.model.Balance import net.dankito.fints.transactions.mt940.model.TransactionDetails import net.dankito.fints.transactions.mt940.model.Turnover @@ -11,7 +11,7 @@ import java.text.SimpleDateFormat import java.util.* -class Mt940AccountTransactionsParserTest { +class Mt940ParserTest { companion object { const val TestFilesFolderName = "test_files/" @@ -43,14 +43,14 @@ class Mt940AccountTransactionsParserTest { val AccountStatement1With2TransactionsClosingBalanceAmount = AccountStatement1OpeningBalanceAmount + AccountStatement1Transaction1Amount - AccountStatement1Transaction2Amount } - private val underTest = Mt940AccountTransactionsParser() + private val underTest = Mt940Parser() @Test fun accountStatementWithSingleTransaction() { // when - val result = underTest.parseTransactions(AccountStatementWithSingleTransaction) + val result = underTest.parseMt940String(AccountStatementWithSingleTransaction) // then @@ -75,7 +75,7 @@ class Mt940AccountTransactionsParserTest { fun accountStatementWithTwoTransactions() { // when - val result = underTest.parseTransactions(AccountStatementWithTwoTransactions) + val result = underTest.parseMt940String(AccountStatementWithTwoTransactions) // then @@ -105,12 +105,12 @@ class Mt940AccountTransactionsParserTest { fun parseTransactions() { // given - val fileStream = Mt940AccountTransactionsParserTest::class.java.classLoader.getResourceAsStream(TransactionsMt940FileRelativePath) + val fileStream = Mt940ParserTest::class.java.classLoader.getResourceAsStream(TransactionsMt940FileRelativePath) val transactionsString = fileStream.reader().readText() // when - val result = underTest.parseTransactions(transactionsString) + val result = underTest.parseMt940String(transactionsString) // then @@ -182,7 +182,7 @@ class Mt940AccountTransactionsParserTest { } private fun convertDate(date: Date): String { - return Mt940AccountTransactionsParser.DateFormat.format(date) + return Mt940Parser.DateFormat.format(date) } private fun convertToShortBookingDate(date: Date): String {