From 8ee35ad285afaede258cb59a616218a22d4f9646 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 22 Jan 2013 09:55:29 +0100 Subject: [PATCH] Make posts (more or less) immutable. --- .../sone/data/impl/PostBuilderImpl.java | 2 +- .../net/pterodactylus/sone/data/impl/PostImpl.java | 99 ++-------------------- 2 files changed, 9 insertions(+), 92 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/data/impl/PostBuilderImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/PostBuilderImpl.java index 967de9d..92b80c5 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/PostBuilderImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/PostBuilderImpl.java @@ -143,7 +143,7 @@ public class PostBuilderImpl implements PostBuilder { checkState((currentTime && (time == 0)) || (!currentTime && (time > 0)), "one of current time or custom time must be set"); checkState(!StringUtils.isBlank(text), "text must not be empty"); checkState((recipient == null) || !recipient.equals(sender), "sender and recipient must not be the same"); - return new PostImpl(randomId ? UUID.randomUUID().toString() : id, sender, currentTime ? System.currentTimeMillis() : time, text).setRecipient(recipient); + return new PostImpl(randomId ? UUID.randomUUID().toString() : id, sender, recipient, currentTime ? System.currentTimeMillis() : time, text); } } diff --git a/src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java index 2cc0b00..43d7d79 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java @@ -34,16 +34,16 @@ public class PostImpl implements Post { private final UUID id; /** The Sone this post belongs to. */ - private volatile Sone sone; + private final Sone sone; /** The Sone of the recipient. */ - private volatile Sone recipient; + private final Sone recipient; /** The time of the post (in milliseconds since Jan 1, 1970 UTC). */ - private volatile long time; + private final long time; /** The text of the post. */ - private volatile String text; + private final String text; /** Whether the post is known. */ private volatile boolean known; @@ -53,52 +53,19 @@ public class PostImpl implements Post { * * @param id * The ID of the post - */ - public PostImpl(String id) { - this(id, null, 0, null); - } - - /** - * Creates a new post. - * - * @param sone - * The Sone this post belongs to - * @param text - * The text of the post - */ - public PostImpl(Sone sone, String text) { - this(sone, System.currentTimeMillis(), text); - } - - /** - * Creates a new post. - * - * @param sone - * The Sone this post belongs to - * @param time - * The time of the post (in milliseconds since Jan 1, 1970 UTC) - * @param text - * The text of the post - */ - public PostImpl(Sone sone, long time, String text) { - this(UUID.randomUUID().toString(), sone, time, text); - } - - /** - * Creates a new post. - * - * @param id - * The ID of the post * @param sone * The Sone this post belongs to + * @param recipient + * The recipient of the post * @param time * The time of the post (in milliseconds since Jan 1, 1970 UTC) * @param text * The text of the post */ - public PostImpl(String id, Sone sone, long time, String text) { + public PostImpl(String id, Sone sone, Sone recipient, long time, String text) { this.id = UUID.fromString(id); this.sone = sone; + this.recipient = recipient; this.time = time; this.text = text; } @@ -124,18 +91,6 @@ public class PostImpl implements Post { } /** - * Sets the Sone of this post. - * - * @param sone - * The Sone of this post - * @return This post (for method chaining) - */ - public PostImpl setSone(Sone sone) { - this.sone = sone; - return this; - } - - /** * {@inheritDoc} */ @Override @@ -144,20 +99,6 @@ public class PostImpl implements Post { } /** - * Sets the recipient of this post. - * - * @param recipient - * The recipient of this post, or {@code null} - * @return This post (for method chaining) - */ - public PostImpl setRecipient(Sone recipient) { - if (!sone.equals(recipient)) { - this.recipient = recipient; - } - return this; - } - - /** * {@inheritDoc} */ @Override @@ -166,18 +107,6 @@ public class PostImpl implements Post { } /** - * Sets the time of this post. - * - * @param time - * The time of this post (in milliseconds since Jan 1, 1970 UTC) - * @return This post (for method chaining) - */ - public PostImpl setTime(long time) { - this.time = time; - return this; - } - - /** * {@inheritDoc} */ @Override @@ -186,18 +115,6 @@ public class PostImpl implements Post { } /** - * Sets the text of this post. - * - * @param text - * The text of this post - * @return This post (for method chaining) - */ - public PostImpl setText(String text) { - this.text = text; - return this; - } - - /** * {@inheritDoc} */ @Override -- 2.7.4