* @param contexts
* All contexts of the identity
*/
- public void setContexts(Collection<String> contexts);
+ public void setContexts(Set<String> contexts);
/**
* Removes the given context from this identity.
override fun hasContext(context: String) = context in contexts
- override fun setContexts(contexts: Collection<String>) {
+ override fun setContexts(contexts: Set<String>) {
synchronized(this.contexts) {
this.contexts.clear()
this.contexts.addAll(contexts)
val insertUri = fields.get("InsertURI$ownIdentityCounter")
val nickname = fields.get("Nickname$ownIdentityCounter")
val ownIdentity = DefaultOwnIdentity(id, nickname, requestUri, insertUri)
- ownIdentity.setContexts(fields.contexts("Contexts$ownIdentityCounter."))
+ ownIdentity.contexts = fields.contexts("Contexts$ownIdentityCounter.")
ownIdentity.properties = fields.properties("Properties$ownIdentityCounter.")
ownIdentities.add(ownIdentity)
}
val nickname = fields.get("Nickname$identityCounter")
val requestUri = fields.get("RequestURI$identityCounter")
val identity = DefaultIdentity(id, nickname, requestUri)
- identity.setContexts(fields.contexts("Contexts$identityCounter."))
+ identity.contexts = fields.contexts("Contexts$identityCounter.")
identity.properties = fields.properties("Properties$identityCounter.")
val trust = parseInt(fields.get("Trust$identityCounter"), null)
val score = parseInt(fields.get("Score$identityCounter"), 0)!!
generateSequence(0, Int::inc)
.map { get("${prefix}Context$it") }
.takeWhile { it != null }
- .toList()
+ .toSet()
private fun SimpleFieldSet.properties(prefix: String) =
generateSequence(0, Int::inc)
@Test
fun `contexts are set correctly in bulk`() {
identity.addContext("Test")
- identity.setContexts(listOf("Test1", "Test2"))
+ identity.contexts = setOf("Test1", "Test2")
assertThat(identity.contexts, containsInAnyOrder("Test1", "Test2"))
assertThat(identity.hasContext("Test"), equalTo(false))
assertThat(identity.hasContext("Test1"), equalTo(true))
package net.pterodactylus.sone.freenet.wot
-fun createOwnIdentity(id: String, contexts: Collection<String>, vararg properties: Pair<String, String>): OwnIdentity {
+fun createOwnIdentity(id: String, contexts: Set<String>, vararg properties: Pair<String, String>): OwnIdentity {
val ownIdentity = DefaultOwnIdentity(id, "Nickname$id", "Request$id", "Insert$id")
setContextsAndPropertiesOnIdentity(ownIdentity, contexts, mapOf(*properties))
return ownIdentity
}
-fun createIdentity(id: String, contexts: Collection<String>, vararg properties: Pair<String, String>): Identity {
+fun createIdentity(id: String, contexts: Set<String>, vararg properties: Pair<String, String>): Identity {
val identity = DefaultIdentity(id, "Nickname$id", "Request$id")
setContextsAndPropertiesOnIdentity(identity, contexts, mapOf(*properties))
return identity
}
-private fun setContextsAndPropertiesOnIdentity(identity: Identity, contexts: Collection<String>, properties: Map<String, String>) {
- identity.setContexts(contexts)
+private fun setContextsAndPropertiesOnIdentity(identity: Identity, contexts: Set<String>, properties: Map<String, String>) {
+ identity.contexts = contexts
identity.properties = properties
}
listOf(createIdentity1(), createIdentity2(), createIdentity3())
private fun createIdentity1() =
- createIdentity("Test1", listOf("Context A", "Context B"), "Key A" to "Value A", "Key B" to "Value B")
+ createIdentity("Test1", setOf("Context A", "Context B"), "Key A" to "Value A", "Key B" to "Value B")
private fun createIdentity2() =
- createIdentity("Test2", listOf("Context C", "Context D"), "Key C" to "Value C", "Key D" to "Value D")
+ createIdentity("Test2", setOf("Context C", "Context D"), "Key C" to "Value C", "Key D" to "Value D")
private fun createIdentity3() =
- createIdentity("Test3", listOf("Context E", "Context F"), "Key E" to "Value E", "Key F" to "Value F")
+ createIdentity("Test3", setOf("Context E", "Context F"), "Key E" to "Value E", "Key F" to "Value F")
private fun createIdentity4() =
- createIdentity("Test4", listOf("Context G", "Context H"), "Key G" to "Value G", "Key H" to "Value H")
+ createIdentity("Test4", setOf("Context G", "Context H"), "Key G" to "Value G", "Key H" to "Value H")
}
private val eventBus = mock<EventBus>()
private val ownIdentities = listOf(
- createOwnIdentity("O1", listOf("Test"), "KeyA" to "ValueA"),
- createOwnIdentity("O2", listOf("Test2"), "KeyB" to "ValueB"),
- createOwnIdentity("O3", listOf("Test3"), "KeyC" to "ValueC")
+ createOwnIdentity("O1", setOf("Test"), "KeyA" to "ValueA"),
+ createOwnIdentity("O2", setOf("Test2"), "KeyB" to "ValueB"),
+ createOwnIdentity("O3", setOf("Test3"), "KeyC" to "ValueC")
)
private val identities = listOf(
- createIdentity("I1", listOf()),
- createIdentity("I2", listOf()),
- createIdentity("I3", listOf()),
- createIdentity("I2", listOf("Test"))
+ createIdentity("I1", setOf()),
+ createIdentity("I2", setOf()),
+ createIdentity("I3", setOf()),
+ createIdentity("I2", setOf("Test"))
)
private val identityChangeEventSender = IdentityChangeEventSender(eventBus, createOldIdentities())
}
private fun createOwnIdentities() = listOf(
- createOwnIdentity("O1", "ON1", "OR1", "OI1", listOf("Test", "Test2"), mapOf("KeyA" to "ValueA", "KeyB" to "ValueB")),
- createOwnIdentity("O2", "ON2", "OR2", "OI2", listOf("Test"), mapOf("KeyC" to "ValueC")),
- createOwnIdentity("O3", "ON3", "OR3", "OI3", listOf("Test2"), mapOf("KeyE" to "ValueE", "KeyD" to "ValueD")),
- createOwnIdentity("O4", "ON4", "OR$", "OI4", listOf("Test"), mapOf("KeyA" to "ValueA", "KeyD" to "ValueD"))
+ createOwnIdentity("O1", "ON1", "OR1", "OI1", setOf("Test", "Test2"), mapOf("KeyA" to "ValueA", "KeyB" to "ValueB")),
+ createOwnIdentity("O2", "ON2", "OR2", "OI2", setOf("Test"), mapOf("KeyC" to "ValueC")),
+ createOwnIdentity("O3", "ON3", "OR3", "OI3", setOf("Test2"), mapOf("KeyE" to "ValueE", "KeyD" to "ValueD")),
+ createOwnIdentity("O4", "ON4", "OR$", "OI4", setOf("Test"), mapOf("KeyA" to "ValueA", "KeyD" to "ValueD"))
)
private fun createTrustedIdentitiesForFirstOwnIdentity() = setOf(
- createIdentity("I11", "IN11", "IR11", listOf("Test"), mapOf("KeyA" to "ValueA"))
+ createIdentity("I11", "IN11", "IR11", setOf("Test"), mapOf("KeyA" to "ValueA"))
)
private fun createTrustedIdentitiesForSecondOwnIdentity() = setOf(
- createIdentity("I21", "IN21", "IR21", listOf("Test", "Test2"), mapOf("KeyB" to "ValueB"))
+ createIdentity("I21", "IN21", "IR21", setOf("Test", "Test2"), mapOf("KeyB" to "ValueB"))
)
private fun createTrustedIdentitiesForThirdOwnIdentity() = setOf(
- createIdentity("I31", "IN31", "IR31", listOf("Test", "Test3"), mapOf("KeyC" to "ValueC"))
+ createIdentity("I31", "IN31", "IR31", setOf("Test", "Test3"), mapOf("KeyC" to "ValueC"))
)
private fun createTrustedIdentitiesForFourthOwnIdentity(): Set<Identity> = emptySet()
-private fun createOwnIdentity(id: String, nickname: String, requestUri: String, insertUri: String, contexts: List<String>, properties: Map<String, String>): OwnIdentity =
+private fun createOwnIdentity(id: String, nickname: String, requestUri: String, insertUri: String, contexts: Set<String>, properties: Map<String, String>): OwnIdentity =
DefaultOwnIdentity(id, nickname, requestUri, insertUri).apply {
setContexts(contexts)
this.properties = properties
}
-private fun createIdentity(id: String, nickname: String, requestUri: String, contexts: List<String>, properties: Map<String, String>): Identity =
+private fun createIdentity(id: String, nickname: String, requestUri: String, contexts: Set<String>, properties: Map<String, String>): Identity =
DefaultIdentity(id, nickname, requestUri).apply {
setContexts(contexts)
this.properties = properties