From af00a04cc0a8ff34e80df91b4796466525ee2a02 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 5 Jul 2023 17:36:24 +0200 Subject: [PATCH] Improve legibility of CertificationSet code --- .../wot/dijkstra/sq/CertificationSet.kt | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/CertificationSet.kt b/wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/CertificationSet.kt index c1d397e6..47c55b6a 100644 --- a/wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/CertificationSet.kt +++ b/wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/CertificationSet.kt @@ -90,26 +90,23 @@ class CertificationSet( require(issuer.fingerprint == certification.issuer.fingerprint) { "Issuer fingerprint mismatch." } require(target.fingerprint == certification.target.fingerprint) { "Target fingerprint mismatch." } - var certificationsForUserId: MutableList? = _certifications[certification.userId] - if (certificationsForUserId == null) { - certificationsForUserId = ArrayList() - _certifications[certification.userId] = certificationsForUserId - } - + val certificationsForUserId = _certifications.getOrPut(certification.userId) { mutableListOf() } if (certificationsForUserId.isEmpty()) { certificationsForUserId.add(certification) return } val existing = certificationsForUserId[0] + // if existing is older than this certification if (existing.creationTime.before(certification.creationTime)) { - certificationsForUserId.clear() // throw away older certifications + // throw away older certifications + certificationsForUserId.clear() } - // If our certification is newest + // If this certification is newest (or equally old!) if (!existing.creationTime.after(certification.creationTime)) { certificationsForUserId.add(certification) } - // else this certification is older, so ignore + // else this certification is older, so don't add it } override fun toString(): String {