From: David ‘Bombe’ Roden Date: Tue, 22 Jan 2013 08:55:29 +0000 (+0100) Subject: Make posts (more or less) immutable. X-Git-Tag: 0.8.5^2~3^2~45^2~8 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=8ee35ad285afaede258cb59a616218a22d4f9646;p=Sone.git Make posts (more or less) immutable. --- 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