From 5e474d0d5ee39c2fd3dfd4376308ad7f8e55dd5d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 30 Oct 2010 01:39:35 +0200 Subject: [PATCH] =?utf8?q?Don=E2=80=99t=20cache=20contexts.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../pterodactylus/sone/freenet/wot/Identity.java | 37 ++++------------------ .../sone/freenet/wot/OwnIdentity.java | 8 ++--- 2 files changed, 8 insertions(+), 37 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/Identity.java b/src/main/java/net/pterodactylus/sone/freenet/wot/Identity.java index b8734c7..60e24d6 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/Identity.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/Identity.java @@ -19,7 +19,6 @@ package net.pterodactylus.sone.freenet.wot; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -42,12 +41,6 @@ public class Identity { /** The request URI of the identity. */ private final String requestUri; - /** The contexts of the identity. */ - protected final Set contexts = Collections.synchronizedSet(new HashSet()); - - /** Whether the contexts have already been loaded. */ - private volatile boolean contextsLoaded = false; - /** The properties of the identity. */ protected final Map properties = Collections.synchronizedMap(new HashMap()); @@ -107,33 +100,12 @@ public class Identity { * set is returned. * * @return The contexts of the identity - */ - public Set getContexts() { - try { - return getContexts(false); - } catch (PluginException pe1) { - return Collections.emptySet(); - } - } - - /** - * Returns the contexts of the identity. - * - * @param forceReload - * {@code true} to force a reload of the contexts - * @return The contexts of the identity * @throws PluginException * if an error occured communicating with the Web of Trust * plugin */ - public Set getContexts(boolean forceReload) throws PluginException { - if (!contextsLoaded || forceReload) { - Set contexts = webOfTrustConnector.loadIdentityContexts(this); - contextsLoaded = true; - this.contexts.clear(); - this.contexts.addAll(contexts); - } - return Collections.unmodifiableSet(contexts); + public Set getContexts() throws PluginException { + return webOfTrustConnector.loadIdentityContexts(this); } /** @@ -143,8 +115,11 @@ public class Identity { * The context to check for * @return {@code true} if this identity has the given context, * {@code false} otherwise + * @throws PluginException + * if an error occured communicating with the Web of Trust + * plugin */ - public boolean hasContext(String context) { + public boolean hasContext(String context) throws PluginException { return getContexts().contains(context); } diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/OwnIdentity.java b/src/main/java/net/pterodactylus/sone/freenet/wot/OwnIdentity.java index a8f24cb..2384520 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/OwnIdentity.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/OwnIdentity.java @@ -70,9 +70,7 @@ public class OwnIdentity extends Identity { * plugin */ public void addContext(String context) throws PluginException { - if (getContexts().add(context)) { - webOfTrustConnector.addContext(this, context); - } + webOfTrustConnector.addContext(this, context); } /** @@ -85,9 +83,7 @@ public class OwnIdentity extends Identity { * plugin */ public void removeContext(String context) throws PluginException { - if (getContexts().remove(context)) { - webOfTrustConnector.removeContext(this, context); - } + webOfTrustConnector.removeContext(this, context); } /** -- 2.7.4