From aff95e127538dfb150df50ef75caf392702e4d07 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 24 Jan 2024 12:07:21 +0300 Subject: [PATCH] Handle 'UnparseableLine' in 'bufferedTransform' --- src/commonMain/kotlin/dogcat/LogLines.kt | 34 +++++++++++++++++------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/commonMain/kotlin/dogcat/LogLines.kt b/src/commonMain/kotlin/dogcat/LogLines.kt index 9a8a83d..3f01f62 100644 --- a/src/commonMain/kotlin/dogcat/LogLines.kt +++ b/src/commonMain/kotlin/dogcat/LogLines.kt @@ -55,25 +55,39 @@ class LogLines( .map { lineParser.parse(it) } - .filterIsInstance() + //.filterIsInstance() .bufferedTransform( { buffer, item -> - when { - buffer.isNotEmpty() -> { - val previous = buffer[0] + when (item) { + is Brief -> { when { - item.tag.contains(previous.tag) -> false - else -> true + buffer.isNotEmpty() -> { + val previous = buffer[0] + when { + //previous == null -> false + (previous as? Brief)?.tag?.contains(item.tag) ?: false -> false + //item.tag.contains((previous as? Brief).tag) -> false + else -> true + } + } + else -> false } } + is Unparseable -> false // Pass through Unparseable items else -> false } }, { buffer, item -> - if (buffer.isEmpty()) { - item - } else { - Brief(item.level, "", item.owner, item.message) + when (item) { + is Brief -> { + if (buffer.isEmpty()) { + item + } else { + Brief(item.level, "", item.owner, item.message) + } + } + is Unparseable -> item // Pass through Unparseable items + else -> item } } )