From: David ‘Bombe’ Roden Date: Tue, 22 Jan 2013 08:46:05 +0000 (+0100) Subject: Make replies (more or less) immutable after creation. X-Git-Tag: 0.8.5^2~3^2~45^2~9 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=83ceb7c20927ae3cd9eb12d8d885462ac66ea6a4 Make replies (more or less) immutable after creation. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 8172b45..5e8bc26 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -1130,7 +1130,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, Set 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()); diff --git a/src/main/java/net/pterodactylus/sone/data/PostReply.java b/src/main/java/net/pterodactylus/sone/data/PostReply.java index 4452e2e..3dd0a14 100644 --- a/src/main/java/net/pterodactylus/sone/data/PostReply.java +++ b/src/main/java/net/pterodactylus/sone/data/PostReply.java @@ -32,13 +32,4 @@ public interface PostReply extends Reply { */ 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); - } diff --git a/src/main/java/net/pterodactylus/sone/data/Reply.java b/src/main/java/net/pterodactylus/sone/data/Reply.java index c23426a..a686023 100644 --- a/src/main/java/net/pterodactylus/sone/data/Reply.java +++ b/src/main/java/net/pterodactylus/sone/data/Reply.java @@ -71,15 +71,6 @@ public interface Reply> { 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> { 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> { 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 diff --git a/src/main/java/net/pterodactylus/sone/data/impl/PostReplyBuilderImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/PostReplyBuilderImpl.java index 18ce200..c4e6bff 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/PostReplyBuilderImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/PostReplyBuilderImpl.java @@ -72,11 +72,6 @@ public class PostReplyBuilderImpl extends AbstractReplyBuilder 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); } } diff --git a/src/main/java/net/pterodactylus/sone/data/impl/PostReplyImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/PostReplyImpl.java index 361a2e9..e7b6626 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/PostReplyImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/PostReplyImpl.java @@ -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 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 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 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; - } - } diff --git a/src/main/java/net/pterodactylus/sone/data/impl/ReplyImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/ReplyImpl.java index 0c052ca..ee8c01e 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/ReplyImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/ReplyImpl.java @@ -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> implements Reply { 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> implements Reply { } /** - * 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> implements Reply { } /** - * 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> implements Reply { } /** - * 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