Make replies (more or less) immutable after creation.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 22 Jan 2013 08:46:05 +0000 (09:46 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 22 Jan 2013 08:46:05 +0000 (09:46 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/data/PostReply.java
src/main/java/net/pterodactylus/sone/data/Reply.java
src/main/java/net/pterodactylus/sone/data/impl/PostReplyBuilderImpl.java
src/main/java/net/pterodactylus/sone/data/impl/PostReplyImpl.java
src/main/java/net/pterodactylus/sone/data/impl/ReplyImpl.java

index 8172b45..5e8bc26 100644 (file)
@@ -1130,7 +1130,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                                Set<PostReply> storedReplies = storedSone.getReplies();
                                synchronized (knownReplies) {
                                        for (PostReply reply : sone.getReplies()) {
-                                               reply.setSone(storedSone).setKnown(knownReplies.contains(reply.getId()));
+                                               reply.setKnown(knownReplies.contains(reply.getId()));
                                                if (!storedReplies.contains(reply)) {
                                                        if (reply.getTime() < getSoneFollowingTime(sone)) {
                                                                knownReplies.add(reply.getId());
index 4452e2e..3dd0a14 100644 (file)
@@ -32,13 +32,4 @@ public interface PostReply extends Reply<PostReply> {
         */
        public Post getPost();
 
-       /**
-        * Sets the post this reply refers to.
-        *
-        * @param postId
-        *            The ID of the post to reply to
-        * @return This reply
-        */
-       public PostReply setPost(String postId);
-
 }
index c23426a..a686023 100644 (file)
@@ -71,15 +71,6 @@ public interface Reply<T extends Reply<T>> {
        public Sone getSone();
 
        /**
-        * Sets the Sone that posted this reply.
-        *
-        * @param sone
-        *            The Sone that posted this reply
-        * @return This reply
-        */
-       public T setSone(Sone sone);
-
-       /**
         * Returns the time of the reply.
         *
         * @return The time of the reply (in milliseconds since Jan 1, 1970 UTC)
@@ -87,15 +78,6 @@ public interface Reply<T extends Reply<T>> {
        public long getTime();
 
        /**
-        * Sets the time of the reply.
-        *
-        * @param time
-        *            The time of the reply (in milliseconds since Jan 1, 1970 UTC)
-        * @return This reply
-        */
-       public T setTime(long time);
-
-       /**
         * Returns the text of the reply.
         *
         * @return The text of the reply
@@ -103,15 +85,6 @@ public interface Reply<T extends Reply<T>> {
        public String getText();
 
        /**
-        * Sets the text of the reply.
-        *
-        * @param text
-        *            The text of the reply
-        * @return This reply
-        */
-       public T setText(String text);
-
-       /**
         * Returns whether this reply is known.
         *
         * @return {@code true} if this reply is known, {@code false} otherwise
index 18ce200..c4e6bff 100644 (file)
@@ -72,11 +72,6 @@ public class PostReplyBuilderImpl extends AbstractReplyBuilder<PostReplyBuilder>
                checkState(postId != null, "post must not be null");
 
                /* create new post reply. */
-               PostReplyImpl postReplyImpl = new PostReplyImpl(postProvider, randomId ? UUID.randomUUID().toString() : id);
-               postReplyImpl.setSone(sender);
-               postReplyImpl.setPost(postId);
-               postReplyImpl.setTime(currentTime ? System.currentTimeMillis() : time);
-               postReplyImpl.setText(text);
-               return postReplyImpl;
+               return new PostReplyImpl(postProvider, randomId ? UUID.randomUUID().toString() : id, sender, currentTime ? System.currentTimeMillis() : time, text, postId);
        }
 }
index 361a2e9..e7b6626 100644 (file)
@@ -20,6 +20,7 @@ package net.pterodactylus.sone.data.impl;
 import net.pterodactylus.sone.core.PostProvider;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
+import net.pterodactylus.sone.data.Sone;
 
 /**
  * Simple {@link PostReply} implementation.
@@ -32,7 +33,7 @@ public class PostReplyImpl extends ReplyImpl<PostReply> implements PostReply {
        private final PostProvider postProvider;
 
        /** The Post this reply refers to. */
-       private volatile String postId;
+       private final String postId;
 
        /**
         * Creates a new reply.
@@ -41,9 +42,17 @@ public class PostReplyImpl extends ReplyImpl<PostReply> implements PostReply {
         *            The post provider
         * @param id
         *            The ID of the reply
+        * @param sone
+        *            The Sone of the reply
+        * @param time
+        *            The time of the reply
+        * @param text
+        *            The text of the reply
+        * @param postId
+        *            The ID of the post this reply refers to
         */
-       public PostReplyImpl(PostProvider postProvider, String id) {
-               super(id);
+       public PostReplyImpl(PostProvider postProvider, String id, Sone sone, long time, String text, String postId) {
+               super(id, sone, time, text);
                this.postProvider = postProvider;
                this.postId = postId;
        }
@@ -60,17 +69,4 @@ public class PostReplyImpl extends ReplyImpl<PostReply> implements PostReply {
                return postProvider.getPost(postId);
        }
 
-       /**
-        * Sets the post this reply refers to.
-        *
-        * @param postId
-        *            The ID of the post to reply to
-        * @return This reply (for method chaining)
-        */
-       @Override
-       public PostReply setPost(String postId) {
-               this.postId = postId;
-               return this;
-       }
-
 }
index 0c052ca..ee8c01e 100644 (file)
@@ -17,8 +17,6 @@
 
 package net.pterodactylus.sone.data.impl;
 
-import java.util.UUID;
-
 import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.Sone;
 
@@ -35,42 +33,18 @@ public abstract class ReplyImpl<T extends Reply<T>> implements Reply<T> {
        private final String id;
 
        /** The Sone that created this reply. */
-       private volatile Sone sone;
+       private final Sone sone;
 
        /** The time of the reply. */
-       private volatile long time;
+       private final long time;
 
        /** The text of the reply. */
-       private volatile String text;
+       private final String text;
 
        /** Whether the reply is known. */
        private volatile boolean known;
 
        /**
-        * Creates a new reply with the given ID.
-        *
-        * @param id
-        *            The ID of the reply
-        */
-       protected ReplyImpl(String id) {
-               this(id, null, 0, null);
-       }
-
-       /**
-        * Creates a new reply with a new random ID.
-        *
-        * @param sone
-        *            The Sone of the reply
-        * @param time
-        *            The time of the reply
-        * @param text
-        *            The text of the reply
-        */
-       protected ReplyImpl(Sone sone, long time, String text) {
-               this(UUID.randomUUID().toString(), sone, time, text);
-       }
-
-       /**
         * Creates a new reply.
         *
         * @param id
@@ -106,20 +80,6 @@ public abstract class ReplyImpl<T extends Reply<T>> implements Reply<T> {
        }
 
        /**
-        * Sets the Sone that posted this reply.
-        *
-        * @param sone
-        *            The Sone that posted this reply
-        * @return This reply (for method chaining)
-        */
-       @Override
-       @SuppressWarnings("unchecked")
-       public T setSone(Sone sone) {
-               this.sone = sone;
-               return (T) this;
-       }
-
-       /**
         * {@inheritDoc}
         */
        @Override
@@ -128,20 +88,6 @@ public abstract class ReplyImpl<T extends Reply<T>> implements Reply<T> {
        }
 
        /**
-        * Sets the time of this reply.
-        *
-        * @param time
-        *            The time of this reply (in milliseconds since Jan 1, 1970 UTC)
-        * @return This reply (for method chaining)
-        */
-       @Override
-       @SuppressWarnings("unchecked")
-       public T setTime(long time) {
-               this.time = time;
-               return (T) this;
-       }
-
-       /**
         * {@inheritDoc}
         */
        @Override
@@ -150,20 +96,6 @@ public abstract class ReplyImpl<T extends Reply<T>> implements Reply<T> {
        }
 
        /**
-        * Sets the text of this reply.
-        *
-        * @param text
-        *            The text of this reply
-        * @return This reply (for method chaining)
-        */
-       @Override
-       @SuppressWarnings("unchecked")
-       public T setText(String text) {
-               this.text = text;
-               return (T) this;
-       }
-
-       /**
         * {@inheritDoc}
         */
        @Override