Skip to content

Instantly share code, notes, and snippets.

@eutkin
Created October 12, 2021 19:56
Show Gist options
  • Save eutkin/7cf21b86176d32775bc9df7631770990 to your computer and use it in GitHub Desktop.
Save eutkin/7cf21b86176d32775bc9df7631770990 to your computer and use it in GitHub Desktop.
import java.time.Instant
import java.util.*
fun main(args: Array<String>) {
var historyStructure = listOf("id", "timestamp", "subtype")
val list = mutableListOf<Map<String, Any?>>()
val event = mapOf(
"id" to UUID.randomUUID(),
"timestamp" to Instant.now().toEpochMilli(),
"subtype" to "PAYMENT~INTERNAL"
)
val record = event
.filterKeys { key -> key in historyStructure }
list.add(record)
val event1 = mapOf(
"id" to UUID.randomUUID(),
"timestamp" to Instant.now().toEpochMilli(),
"subtype" to null
)
val record1 = event1
.filterKeys { key -> key in historyStructure }
list.add(record1)
var count = 0
list.forEach { storedRecord ->
if (storedRecord["subtype"] == "PAYMENT~INTERNAL") {
count++
}
}
println(count)
historyStructure = historyStructure.toMutableList().apply { this.add("simId") }
var count1 = 0
list.forEach { storedRecord ->
if (storedRecord["simId"] == "test-sim") {
count1++
}
}
println(count1)
val event2 = mapOf(
"id" to UUID.randomUUID(),
"timestamp" to Instant.now().toEpochMilli(),
"subtype" to null,
"simId" to "test-sim"
)
val record2 = event2
.filterKeys { key -> key in historyStructure }
list.add(record2)
var count2 = 0
list.forEach { storedRecord ->
if (storedRecord["simId"] == "test-sim") {
count2++
}
}
println(count2)
historyStructure = historyStructure.toMutableList().apply { this.remove("subtype") }
val event3 = mapOf(
"id" to UUID.randomUUID(),
"timestamp" to Instant.now().toEpochMilli(),
"subtype" to "PAYMENT~EXTERNAL",
"simId" to "test-sim"
)
val record3 = event3
.filterKeys { key -> key in historyStructure }
list.add(record3)
var count3 = 0
list.forEach { storedRecord ->
if (storedRecord["simId"] == "test-sim") {
count3++
}
}
println(count3)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment