From 2dcc1ae56efa3a286376e4e8dc2ec3d1dd42c5a9 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Mon, 3 Jul 2023 15:03:27 +0200 Subject: [PATCH] Transform CertificationSet.certifications to backing property to achieve read-onlyness --- .../wot/dijkstra/sq/CertificationSet.kt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 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 e31f138d..4c23f040 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 @@ -11,14 +11,22 @@ package org.pgpainless.wot.dijkstra.sq * * @param issuer synopsis of the certificate that issued the [Certifications][Certification] * @param target synopsis of the certificate that is targeted by the [Certifications][Certification] - * @param certifications [MutableMap] keyed by user-ids, whose values are [MutableLists][MutableList] of + * @param certifications [Map] keyed by user-ids, whose values are [Lists][List] of * [Certifications][Certification] that are calculated over the key user-id. Note, that the key can also be null for * [Certifications][Certification] over the targets primary key. */ -data class CertificationSet( +class CertificationSet( val issuer: CertSynopsis, val target: CertSynopsis, - val certifications: MutableMap>) { + certifications: Map>) { + + init { + certifications.forEach { (t, u) -> _certifications[t] = u.toMutableList() } + } + + private val _certifications: MutableMap> = mutableMapOf() + val certifications: Map> + get() = _certifications.toMutableMap() companion object { @@ -76,10 +84,10 @@ data 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] + var certificationsForUserId: MutableList? = _certifications[certification.userId] if (certificationsForUserId == null) { certificationsForUserId = ArrayList() - certifications[certification.userId] = certificationsForUserId + _certifications[certification.userId] = certificationsForUserId } certificationsForUserId.add(certification) }