X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FSone.java;h=5fd601b45a61993f3f75c0942e19dce3507acfef;hb=4696ccf25ac020842b6072cc11a93b1555542013;hp=3baed89278cde8e756440e097b226282988430ca;hpb=5391ee6663db685d2e6283117ff8a17e91165350;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index 3baed89..5fd601b 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -24,7 +24,10 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.UUID; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.pterodactylus.util.logging.Logging; import freenet.keys.FreenetURI; /** @@ -37,6 +40,9 @@ import freenet.keys.FreenetURI; */ public class Sone { + /** The logger. */ + private static final Logger logger = Logging.getLogger(Sone.class); + /** A GUID for this Sone. */ private final UUID id; @@ -44,11 +50,11 @@ public class Sone { private final String name; /** The URI under which the Sone is stored in Freenet. */ - private final FreenetURI requestUri; + private FreenetURI requestUri; /** The URI used to insert a new version of this Sone. */ /* This will be null for remote Sones! */ - private final FreenetURI insertUri; + private FreenetURI insertUri; /** The profile of this Sone. */ private Profile profile; @@ -238,6 +244,7 @@ public class Sone { */ public synchronized void addPost(Post post) { if (post.getSone().equals(this) && posts.add(post)) { + logger.log(Level.FINEST, "Adding %s to “%s”.", new Object[] { post, getName() }); modificationCounter++; } } @@ -307,6 +314,19 @@ public class Sone { this.modificationCounter = modificationCounter; } + /** + * Updates the suggested edition in both the request URI and the insert URI. + * + * @param requestUri + * The request URI that resulted from an insert + */ + public void updateUris(FreenetURI requestUri) { + /* TODO - check for the correct URI. */ + long latestEdition = requestUri.getSuggestedEdition(); + this.requestUri = this.requestUri.setSuggestedEdition(latestEdition); + this.insertUri = this.insertUri.setSuggestedEdition(latestEdition); + } + // // OBJECT METHODS // @@ -330,4 +350,12 @@ public class Sone { return ((Sone) object).id.equals(id); } + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return getName() + "[id=" + getId() + ",requestUri=" + getRequestUri() + ",insertUri=" + getInsertUri() + ",posts(" + posts.size() + "),replies(" + replies.size() + ")]"; + } + }