Made remainder nullable to signal there is no remainder

This commit is contained in:
dankito 2024-09-10 18:21:12 +02:00
parent e260eaa535
commit 2031cb9e9f
6 changed files with 7 additions and 7 deletions

View File

@ -217,7 +217,7 @@ open class FinTsJobExecutor(
context.bank, parameter.account) context.bank, parameter.account)
bookedTransactions.addAll(chunkTransaction) bookedTransactions.addAll(chunkTransaction)
remainingMt940String = remainder remainingMt940String = remainder ?: ""
parameter.retrievedChunkListener?.invoke(bookedTransactions) parameter.retrievedChunkListener?.invoke(bookedTransactions)
} }

View File

@ -13,6 +13,6 @@ interface IAccountTransactionsParser {
fun parseTransactions(transactionsString: String, bank: BankData, account: AccountData): List<AccountTransaction> fun parseTransactions(transactionsString: String, bank: BankData, account: AccountData): List<AccountTransaction>
fun parseTransactionsChunk(transactionsChunk: String, bank: BankData, account: AccountData): Pair<List<AccountTransaction>, String> fun parseTransactionsChunk(transactionsChunk: String, bank: BankData, account: AccountData): Pair<List<AccountTransaction>, String?>
} }

View File

@ -25,7 +25,7 @@ open class Mt940AccountTransactionsParser(
return accountStatements.flatMap { mapToAccountTransactions(it, bank, account) } return accountStatements.flatMap { mapToAccountTransactions(it, bank, account) }
} }
override fun parseTransactionsChunk(transactionsChunk: String, bank: BankData, account: AccountData): Pair<List<AccountTransaction>, String> { override fun parseTransactionsChunk(transactionsChunk: String, bank: BankData, account: AccountData): Pair<List<AccountTransaction>, String?> {
val (accountStatements, remainder) = mt940Parser.parseMt940Chunk(transactionsChunk) val (accountStatements, remainder) = mt940Parser.parseMt940Chunk(transactionsChunk)
return Pair(accountStatements.flatMap { mapToAccountTransactions(it, bank, account) }, remainder) return Pair(accountStatements.flatMap { mapToAccountTransactions(it, bank, account) }, remainder)

View File

@ -25,6 +25,6 @@ interface IMt940Parser {
* be displayed immediately to user and the remainder then be passed together with next partial * be displayed immediately to user and the remainder then be passed together with next partial
* HKKAZ response to this method till this whole MT 940 statement is parsed. * HKKAZ response to this method till this whole MT 940 statement is parsed.
*/ */
fun parseMt940Chunk(mt940Chunk: String): Pair<List<AccountStatement>, String> fun parseMt940Chunk(mt940Chunk: String): Pair<List<AccountStatement>, String?>
} }

View File

@ -95,11 +95,11 @@ open class Mt940Parser(
* be displayed immediately to user and the remainder then be passed together with next partial * be displayed immediately to user and the remainder then be passed together with next partial
* HKKAZ response to this method till this whole MT 940 statement is parsed. * HKKAZ response to this method till this whole MT 940 statement is parsed.
*/ */
override fun parseMt940Chunk(mt940Chunk: String): Pair<List<AccountStatement>, String> { override fun parseMt940Chunk(mt940Chunk: String): Pair<List<AccountStatement>, String?> {
try { try {
val singleAccountStatementsStrings = splitIntoSingleAccountStatements(mt940Chunk).toMutableList() val singleAccountStatementsStrings = splitIntoSingleAccountStatements(mt940Chunk).toMutableList()
var remainder = "" var remainder: String? = null
if (singleAccountStatementsStrings.isNotEmpty() && singleAccountStatementsStrings.last().isEmpty() == false) { if (singleAccountStatementsStrings.isNotEmpty() && singleAccountStatementsStrings.last().isEmpty() == false) {
remainder = singleAccountStatementsStrings.removeAt(singleAccountStatementsStrings.lastIndex) remainder = singleAccountStatementsStrings.removeAt(singleAccountStatementsStrings.lastIndex)
} }

View File

@ -110,7 +110,7 @@ class Mt940ParserTest : FinTsTestBase() {
// then // then
assertEmpty(remainder) assertNull(remainder)
assertSize(1, statements) assertSize(1, statements)