X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffreenet%2Fwot%2FDefaultOwnIdentity.java;h=ab46b43d1bcbf275af7026c7fa14621487b6d364;hb=a23c4f218c3adf236d89d5927cae37d6e6e4feda;hp=f89ddda2f00ed65e00bcc9ed382023a85342b535;hpb=7379bb70d4db3b419deed77f0df95f74c4b0e038;p=Sone.git 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 f89ddda..ab46b43 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultOwnIdentity.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultOwnIdentity.java @@ -21,6 +21,8 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import net.pterodactylus.util.validation.Validation; + /** * An own identity is an identity that the owner of the node has full control * over. @@ -73,6 +75,7 @@ public class DefaultOwnIdentity extends DefaultIdentity implements OwnIdentity { @Override public void addContext(String context) throws WebOfTrustException { webOfTrustConnector.addContext(this, context); + addContextPrivate(context); } /** @@ -81,6 +84,7 @@ public class DefaultOwnIdentity extends DefaultIdentity implements OwnIdentity { @Override public void removeContext(String context) throws WebOfTrustException { webOfTrustConnector.removeContext(this, context); + removeContextPrivate(context); } /** @@ -98,6 +102,7 @@ public class DefaultOwnIdentity extends DefaultIdentity implements OwnIdentity { webOfTrustConnector.addContext(this, context); } } + setContextsPrivate(contexts); } /** @@ -106,6 +111,7 @@ public class DefaultOwnIdentity extends DefaultIdentity implements OwnIdentity { @Override public void setProperty(String name, String value) throws WebOfTrustException { webOfTrustConnector.setProperty(this, name, value); + setPropertyPrivate(name, value); } /** @@ -114,6 +120,7 @@ public class DefaultOwnIdentity extends DefaultIdentity implements OwnIdentity { @Override public void removeProperty(String name) throws WebOfTrustException { webOfTrustConnector.removeProperty(this, name); + removePropertyPrivate(name); } /** @@ -133,6 +140,53 @@ public class DefaultOwnIdentity extends DefaultIdentity implements OwnIdentity { 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).setTrustPrivate(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).setTrustPrivate(this, new Trust(null, null, null)); + } + } + + // + // 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); } }