Add logging.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Sone.java
index 3baed89..5fd601b 100644 (file)
@@ -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() + ")]";
+       }
+
 }