X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffreenet%2Fwot%2FDefaultOwnIdentity.java;h=68e6f417edcbd7f41a88717fd99d3afca4ebb1f1;hp=6acdd70045d772b515fe472077b9cc8bbfeab7bf;hb=419098bcd6215125408b29e60bd888e60979d37b;hpb=b95f0d80fa0ac4f9f6f8b51b2fecf796a1f72801 diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultOwnIdentity.java b/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultOwnIdentity.java index 6acdd70..68e6f41 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultOwnIdentity.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultOwnIdentity.java @@ -1,5 +1,5 @@ /* - * Sone - DefaultOwnIdentity.java - Copyright © 2010–2012 David Roden + * Sone - DefaultOwnIdentity.java - Copyright © 2010–2015 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,11 +17,7 @@ package net.pterodactylus.sone.freenet.wot; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import net.pterodactylus.util.validation.Validation; +import static com.google.common.base.Preconditions.checkNotNull; /** * An own identity is an identity that the owner of the node has full control @@ -31,17 +27,12 @@ import net.pterodactylus.util.validation.Validation; */ public class DefaultOwnIdentity extends DefaultIdentity implements OwnIdentity { - /** The identity manager. */ - private final WebOfTrustConnector webOfTrustConnector; - /** The insert URI of the identity. */ private final String insertUri; /** * Creates a new own identity. * - * @param webOfTrustConnector - * The identity manager * @param id * The ID of the identity * @param nickname @@ -51,157 +42,51 @@ public class DefaultOwnIdentity extends DefaultIdentity implements OwnIdentity { * @param insertUri * The insert URI of the identity */ - public DefaultOwnIdentity(WebOfTrustConnector webOfTrustConnector, String id, String nickname, String requestUri, String insertUri) { - super(webOfTrustConnector, id, nickname, requestUri); - this.webOfTrustConnector = webOfTrustConnector; - this.insertUri = insertUri; - } - - /** - * Copy constructor for an own identity. - * - * @param webOfTrustConnector - * The web of trust connector - * @param ownIdentity - * The own identity to copy - */ - public DefaultOwnIdentity(WebOfTrustConnector webOfTrustConnector, OwnIdentity ownIdentity) { - super(webOfTrustConnector, ownIdentity.getId(), ownIdentity.getNickname(), ownIdentity.getRequestUri()); - this.webOfTrustConnector = webOfTrustConnector; - this.insertUri = ownIdentity.getInsertUri(); - setContextsPrivate(ownIdentity.getContexts()); - setPropertiesPrivate(ownIdentity.getProperties()); + public DefaultOwnIdentity(String id, String nickname, String requestUri, String insertUri) { + super(id, nickname, requestUri); + this.insertUri = checkNotNull(insertUri); } // // ACCESSORS // - /** - * {@inheritDoc} - */ @Override public String getInsertUri() { return insertUri; } - /** - * {@inheritDoc} - */ @Override - public void addContext(String context) throws WebOfTrustException { - webOfTrustConnector.addContext(this, context); - addContextPrivate(context); + public OwnIdentity addContext(String context) { + return (OwnIdentity) super.addContext(context); } - /** - * {@inheritDoc} - */ @Override - public void removeContext(String context) throws WebOfTrustException { - webOfTrustConnector.removeContext(this, context); - removeContextPrivate(context); + public OwnIdentity removeContext(String context) { + return (OwnIdentity) super.removeContext(context); } - /** - * {@inheritDoc} - */ @Override - public void setContexts(Set contexts) throws WebOfTrustException { - for (String context : getContexts()) { - if (!contexts.contains(context)) { - webOfTrustConnector.removeContext(this, context); - } - } - for (String context : contexts) { - if (!getContexts().contains(context)) { - webOfTrustConnector.addContext(this, context); - } - } - setContextsPrivate(contexts); + public OwnIdentity setProperty(String name, String value) { + return (OwnIdentity) super.setProperty(name, value); } - /** - * {@inheritDoc} - */ @Override - public void setProperty(String name, String value) throws WebOfTrustException { - webOfTrustConnector.setProperty(this, name, value); - setPropertyPrivate(name, value); - } - - /** - * {@inheritDoc} - */ - @Override - public void removeProperty(String name) throws WebOfTrustException { - webOfTrustConnector.removeProperty(this, name); - removePropertyPrivate(name); - } - - /** - * {@inheritDoc} - */ - @Override - public void setProperties(Map properties) throws WebOfTrustException { - for (Entry oldProperty : getProperties().entrySet()) { - if (!properties.containsKey(oldProperty.getKey())) { - webOfTrustConnector.removeProperty(this, oldProperty.getKey()); - } else { - webOfTrustConnector.setProperty(this, oldProperty.getKey(), properties.get(oldProperty.getKey())); - } - } - for (Entry newProperty : properties.entrySet()) { - if (!getProperties().containsKey(newProperty.getKey())) { - webOfTrustConnector.setProperty(this, newProperty.getKey(), newProperty.getValue()); - } - } - setPropertiesPrivate(properties); - } - - /** - * {@inheritDoc} - */ - @Override - public void setTrust(Identity target, int trustValue, String comment) throws WebOfTrustException { - Validation.begin().isNotNull("Trust Target", target).isNotNull("Trust Comment", comment).isLessOrEqual("Trust Value", trustValue, 100).isGreaterOrEqual("Trust Value", trustValue, -100).check(); - webOfTrustConnector.setTrust(this, target, trustValue, comment); - if (target instanceof DefaultIdentity) { - ((DefaultIdentity) target).setTrust(this, new Trust(trustValue, trustValue, 0)); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void removeTrust(Identity target) throws WebOfTrustException { - Validation.begin().isNotNull("Trust Target", target).check(); - webOfTrustConnector.removeTrust(this, target); - if (target instanceof DefaultIdentity) { - ((DefaultIdentity) target).setTrust(this, new Trust(null, null, null)); - } + public OwnIdentity removeProperty(String name) { + return (OwnIdentity) super.removeProperty(name); } // // OBJECT METHODS // - /** - * {@inheritDoc} - */ @Override public int hashCode() { - /* The hash of DefaultIdentity is fine. */ return super.hashCode(); } - /** - * {@inheritDoc} - */ @Override public boolean equals(Object object) { - /* The ID of the superclass is still enough. */ return super.equals(object); }