1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-15 17:02:06 +01:00

Improve legibility of CertificationSet code

This commit is contained in:
Paul Schaub 2023-07-05 17:36:24 +02:00
parent 41f4e3c453
commit f27f1133f7
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -90,26 +90,23 @@ class CertificationSet(
require(issuer.fingerprint == certification.issuer.fingerprint) { "Issuer fingerprint mismatch." } require(issuer.fingerprint == certification.issuer.fingerprint) { "Issuer fingerprint mismatch." }
require(target.fingerprint == certification.target.fingerprint) { "Target fingerprint mismatch." } require(target.fingerprint == certification.target.fingerprint) { "Target fingerprint mismatch." }
var certificationsForUserId: MutableList<Certification>? = _certifications[certification.userId] val certificationsForUserId = _certifications.getOrPut(certification.userId) { mutableListOf() }
if (certificationsForUserId == null) {
certificationsForUserId = ArrayList()
_certifications[certification.userId] = certificationsForUserId
}
if (certificationsForUserId.isEmpty()) { if (certificationsForUserId.isEmpty()) {
certificationsForUserId.add(certification) certificationsForUserId.add(certification)
return return
} }
val existing = certificationsForUserId[0] val existing = certificationsForUserId[0]
// if existing is older than this certification
if (existing.creationTime.before(certification.creationTime)) { 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)) { if (!existing.creationTime.after(certification.creationTime)) {
certificationsForUserId.add(certification) certificationsForUserId.add(certification)
} }
// else this certification is older, so ignore // else this certification is older, so don't add it
} }
override fun toString(): String { override fun toString(): String {