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=be2a3e7d06fe2ea9067b8f49e53377d76983f897;hp=9a104e83e7ac1612018bc016f2cf4d74f567d372;hb=c9e306ac8e3ada846e87a0cc256a20fc148f381c;hpb=1d22fc422cbf5ed74df3081fe3a45b90795fb7c6 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 9a104e8..be2a3e7 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultOwnIdentity.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultOwnIdentity.java @@ -57,6 +57,22 @@ public class DefaultOwnIdentity extends DefaultIdentity implements OwnIdentity { 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()); + } + // // ACCESSORS // @@ -150,6 +166,9 @@ public class DefaultOwnIdentity extends DefaultIdentity implements OwnIdentity { 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)); + } } /** @@ -159,6 +178,31 @@ public class DefaultOwnIdentity extends DefaultIdentity implements OwnIdentity { 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); } }