X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2Fimpl%2FDefaultSone.java;h=92d7d5fd735431b094f11eab8d03666754c9dd29;hb=f3de529dac23aff1f2378930cc5b68f43450a6b3;hp=59964f972e744cf6fef50d6238e4f70884ede70a;hpb=cb7aebca2a351028dd4fdd00dcd637c6aafac79b;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/impl/DefaultSone.java b/src/main/java/net/pterodactylus/sone/data/impl/DefaultSone.java index 59964f9..92d7d5f 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/DefaultSone.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/DefaultSone.java @@ -68,9 +68,6 @@ public class DefaultSone implements Sone { /** Whether the Sone is local. */ private final boolean local; - /** The identity of this Sone. */ - private Identity identity; - /** The URI under which the Sone is stored in Freenet. */ private volatile FreenetURI requestUri; @@ -91,7 +88,7 @@ public class DefaultSone implements Sone { private volatile Profile profile = new Profile(this); /** The client used by the Sone. */ - private volatile Client client; + private final Client client; /** Whether this Sone is known. */ private volatile boolean known; @@ -125,10 +122,11 @@ public class DefaultSone implements Sone { * @param local * {@code true} if the Sone is a local Sone, {@code false} otherwise */ - public DefaultSone(Database database, String id, boolean local) { + public DefaultSone(Database database, String id, boolean local, Client client) { this.database = database; this.id = id; this.local = local; + this.client = client; rootAlbum = new DefaultAlbumBuilder(database, this, null).build(); } @@ -141,19 +139,11 @@ public class DefaultSone implements Sone { } public Identity getIdentity() { - return identity; - } - - public DefaultSone setIdentity(Identity identity) throws IllegalArgumentException { - if (!identity.getId().equals(id)) { - throw new IllegalArgumentException("Identity’s ID does not match Sone’s ID!"); - } - this.identity = identity; - return this; + return database.getIdentity(id).get(); } public String getName() { - return (identity != null) ? identity.getNickname() : null; + return getIdentity().getNickname(); } public boolean isLocal() { @@ -234,11 +224,6 @@ public class DefaultSone implements Sone { return client; } - public Sone setClient(Client client) { - this.client = client; - return this; - } - public boolean isKnown() { return known; } @@ -409,6 +394,23 @@ public class DefaultSone implements Sone { }; } + public Modifier modify() { + return new Modifier() { + private long latestEdition = DefaultSone.this.latestEdition; + @Override + public Modifier setLatestEdition(long latestEdition) { + this.latestEdition = latestEdition; + return this; + } + + @Override + public Sone update() { + DefaultSone.this.latestEdition = latestEdition; + return DefaultSone.this; + } + }; + } + // // FINGERPRINTABLE METHODS // @@ -488,7 +490,7 @@ public class DefaultSone implements Sone { @Override public String toString() { - return getClass().getName() + "[identity=" + identity + ",requestUri=" + requestUri + ",insertUri(" + String.valueOf(insertUri).length() + "),friends(" + friendSones.size() + "),posts(" + posts.size() + "),replies(" + replies.size() + "),albums(" + getRootAlbum().getAlbums().size() + ")]"; + return getClass().getName() + "[id=" + id + ",requestUri=" + requestUri + ",insertUri(" + String.valueOf(insertUri).length() + "),friends(" + friendSones.size() + "),posts(" + posts.size() + "),replies(" + replies.size() + "),albums(" + getRootAlbum().getAlbums().size() + ")]"; } }