X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffreenet%2Fwot%2FDefaultIdentity.java;h=2ef33c3d3b5da14c9d8145fceed7210b89761882;hp=288a99ef066b7c9d19e691cc17289f888558d353;hb=17ed3b897e37c8b16c559b79bfe97d32a7605bfb;hpb=6ab999d8120ca28c4a1cb7370ae9e8ac61504556 diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultIdentity.java b/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultIdentity.java index 288a99e..2ef33c3 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultIdentity.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultIdentity.java @@ -1,5 +1,5 @@ /* - * Sone - DefaultIdentity.java - Copyright © 2010 David Roden + * Sone - DefaultIdentity.java - Copyright © 2010–2012 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,6 +17,7 @@ package net.pterodactylus.sone.freenet.wot; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -45,6 +46,9 @@ public class DefaultIdentity implements Identity { /** The properties of the identity. */ private final Map properties = Collections.synchronizedMap(new HashMap()); + /** Cached trust. */ + private final Map trustCache = Collections.synchronizedMap(new HashMap()); + /** * Creates a new identity. * @@ -98,47 +102,35 @@ public class DefaultIdentity implements Identity { } /** - * Sets the contexts of this identity. - *

- * This method is only called by the {@link IdentityManager}. - * - * @param contexts - * The contexts to set + * {@inheritDoc} */ - void setContextsPrivate(Set contexts) { - this.contexts.clear(); - this.contexts.addAll(contexts); + @Override + public boolean hasContext(String context) { + return contexts.contains(context); } /** * {@inheritDoc} */ @Override - public boolean hasContext(String context) { - return contexts.contains(context); + public void setContexts(Collection contexts) { + this.contexts.clear(); + this.contexts.addAll(contexts); } /** - * Adds the given context to this identity. - *

- * This method is only called by the {@link IdentityManager}. - * - * @param context - * The context to add + * {@inheritDoc} */ - void addContextPrivate(String context) { + @Override + public void addContext(String context) { contexts.add(context); } /** - * Removes the given context from this identity. - *

- * This method is only called by the {@link IdentityManager}. - * - * @param context - * The context to remove + * {@inheritDoc} */ - public void removeContextPrivate(String context) { + @Override + public void removeContext(String context) { contexts.remove(context); } @@ -147,64 +139,64 @@ public class DefaultIdentity implements Identity { */ @Override public Map getProperties() { - synchronized (properties) { - return Collections.unmodifiableMap(properties); - } + return Collections.unmodifiableMap(properties); } /** - * Sets all properties of this identity. - *

- * This method is only called by the {@link IdentityManager}. - * - * @param properties - * The new properties of this identity + * {@inheritDoc} */ - void setPropertiesPrivate(Map properties) { - synchronized (this.properties) { - this.properties.clear(); - this.properties.putAll(properties); - } + @Override + public void setProperties(Map properties) { + this.properties.clear(); + this.properties.putAll(properties); } /** - * Sets the property with the given name to the given value. - *

- * This method is only called by the {@link IdentityManager}. - * - * @param name - * The name of the property - * @param value - * The value of the property - */ - void setPropertyPrivate(String name, String value) { - synchronized (properties) { - properties.put(name, value); - } + * {@inheritDoc} + */ + @Override + public String getProperty(String name) { + return properties.get(name); } /** * {@inheritDoc} */ @Override - public String getProperty(String name) { - synchronized (properties) { - return properties.get(name); - } + public void setProperty(String name, String value) { + properties.put(name, value); } /** - * Removes the property with the given name. - *

- * This method is only called by the {@link IdentityManager}. - * - * @param name - * The name of the property to remove + * {@inheritDoc} */ - void removePropertyPrivate(String name) { - synchronized (properties) { - properties.remove(name); - } + @Override + public void removeProperty(String name) { + properties.remove(name); + } + + /** + * {@inheritDoc} + */ + @Override + public Trust getTrust(OwnIdentity ownIdentity) { + return trustCache.get(ownIdentity); + } + + /** + * {@inheritDoc} + */ + @Override + public void setTrust(OwnIdentity ownIdentity, Trust trust) { + trustCache.put(ownIdentity, trust); + } + + /** + * {@inheritDoc} + */ + @Override + public void removeTrust(OwnIdentity ownIdentity) { + trustCache.remove(ownIdentity); } //