1 package net.pterodactylus.sone.freenet.wot
4 * Filter for identities that retains only those remote identities that do
5 * not have a single negative trust value (explicit or implicit) from any own
8 class NoNegativeIdentityFilter {
10 fun filter(identities: Map<OwnIdentity, Set<Identity>>) =
12 val identitiesWithTrust = values.flatten()
14 .mapValues { (_, identities) ->
15 identities.reduce { accIdentity, identity ->
16 identity.trust.forEach { (ownIdentity: OwnIdentity?, trust: Trust?) ->
17 accIdentity.setTrust(ownIdentity, trust)
23 mapValues { (_, trustedIdentities) ->
24 trustedIdentities.filter { trustedIdentity ->
25 identitiesWithTrust[trustedIdentity.id]!!.trust.all { it.value.hasZeroOrPositiveTrust() }
32 private fun Trust.hasZeroOrPositiveTrust() =
33 if (explicit == null) {
34 implicit == null || implicit >= 0