Fix ALL the logging!
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Sone.java
index 74ab276..e5ebcf1 100644 (file)
@@ -49,6 +49,26 @@ import freenet.keys.FreenetURI;
 public class Sone implements Fingerprintable, Comparable<Sone> {
 
        /**
+        * Enumeration for the possible states of a {@link Sone}.
+        *
+        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
+       public enum SoneStatus {
+
+               /** The Sone is unknown, i.e. not yet downloaded. */
+               unknown,
+
+               /** The Sone is idle, i.e. not being downloaded or inserted. */
+               idle,
+
+               /** The Sone is currently being inserted. */
+               inserting,
+
+               /** The Sone is currently being downloaded. */
+               downloading,
+       }
+
+       /**
         * The possible values for the “show custom avatars” option.
         *
         * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
@@ -171,12 +191,18 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
        /** The time of the last inserted update. */
        private volatile long time;
 
+       /** The status of this Sone. */
+       private volatile SoneStatus status = SoneStatus.unknown;
+
        /** The profile of this Sone. */
        private volatile Profile profile = new Profile(this);
 
        /** The client used by the Sone. */
        private volatile Client client;
 
+       /** Whether this Sone is known. */
+       private volatile boolean known;
+
        /** All friend Sones. */
        private final Set<String> friendSones = new CopyOnWriteArraySet<String>();
 
@@ -279,7 +305,7 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
                        return this;
                }
                if (!this.requestUri.equalsKeypair(requestUri)) {
-                       logger.log(Level.WARNING, "Request URI %s tried to overwrite %s!", new Object[] { requestUri, this.requestUri });
+                       logger.log(Level.WARNING, String.format("Request URI %s tried to overwrite %s!", requestUri, this.requestUri));
                        return this;
                }
                return this;
@@ -307,7 +333,7 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
                        return this;
                }
                if (!this.insertUri.equalsKeypair(insertUri)) {
-                       logger.log(Level.WARNING, "Request URI %s tried to overwrite %s!", new Object[] { insertUri, this.insertUri });
+                       logger.log(Level.WARNING, String.format("Request URI %s tried to overwrite %s!", insertUri, this.insertUri));
                        return this;
                }
                return this;
@@ -332,7 +358,7 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
         */
        public void setLatestEdition(long latestEdition) {
                if (!(latestEdition > this.latestEdition)) {
-                       logger.log(Level.FINE, "New latest edition %d is not greater than current latest edition %d!", new Object[] { latestEdition, this.latestEdition });
+                       logger.log(Level.FINE, String.format("New latest edition %d is not greater than current latest edition %d!", latestEdition, this.latestEdition));
                        return;
                }
                this.latestEdition = latestEdition;
@@ -360,6 +386,30 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
        }
 
        /**
+        * Returns the status of this Sone.
+        *
+        * @return The status of this Sone
+        */
+       public SoneStatus getStatus() {
+               return status;
+       }
+
+       /**
+        * Sets the new status of this Sone.
+        *
+        * @param status
+        *            The new status of this Sone
+        * @return This Sone
+        * @throws IllegalArgumentException
+        *             if {@code status} is {@code null}
+        */
+       public Sone setStatus(SoneStatus status) {
+               Validation.begin().isNotNull("Sone Status", status).check();
+               this.status = status;
+               return this;
+       }
+
+       /**
         * Returns a copy of the profile. If you want to update values in the
         * profile of this Sone, update the values in the returned {@link Profile}
         * and use {@link #setProfile(Profile)} to change the profile in this Sone.
@@ -404,6 +454,27 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
        }
 
        /**
+        * Returns whether this Sone is known.
+        *
+        * @return {@code true} if this Sone is known, {@code false} otherwise
+        */
+       public boolean isKnown() {
+               return known;
+       }
+
+       /**
+        * Sets whether this Sone is known.
+        *
+        * @param known
+        *            {@code true} if this Sone is known, {@code false} otherwise
+        * @return This Sone
+        */
+       public Sone setKnown(boolean known) {
+               this.known = known;
+               return this;
+       }
+
+       /**
         * Returns all friend Sones of this Sone.
         *
         * @return The friend Sones of this Sone
@@ -489,7 +560,7 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
         */
        public void addPost(Post post) {
                if (post.getSone().equals(this) && posts.add(post)) {
-                       logger.log(Level.FINEST, "Adding %s to “%s”.", new Object[] { post, getName() });
+                       logger.log(Level.FINEST, String.format("Adding %s to “%s”.", post, getName()));
                }
        }