Merge commit '173eb2df26ebc15a6aa5565ec15dfad37bfa61a1' into run
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 25 Jan 2013 18:07:55 +0000 (19:07 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 25 Jan 2013 18:07:55 +0000 (19:07 +0100)
Conflicts:
src/main/java/net/pterodactylus/sone/core/Core.java

16 files changed:
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/SoneDownloader.java
src/main/java/net/pterodactylus/sone/data/PostBuilder.java
src/main/java/net/pterodactylus/sone/data/PostReply.java
src/main/java/net/pterodactylus/sone/data/PostReplyBuilder.java
src/main/java/net/pterodactylus/sone/data/Reply.java
src/main/java/net/pterodactylus/sone/data/ReplyBuilder.java
src/main/java/net/pterodactylus/sone/data/impl/AbstractReplyBuilder.java
src/main/java/net/pterodactylus/sone/data/impl/DefaultPostBuilderFactory.java
src/main/java/net/pterodactylus/sone/data/impl/DefaultPostReplyBuilderFactory.java
src/main/java/net/pterodactylus/sone/data/impl/PostBuilderImpl.java
src/main/java/net/pterodactylus/sone/data/impl/PostImpl.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
src/main/java/net/pterodactylus/sone/main/SonePlugin.java

index 7d4441b..ab49612 100644 (file)
@@ -1110,7 +1110,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                                synchronized (knownPosts) {
                                        for (Post post : sone.getPosts()) {
                                                PostBuilder postBuilder = postBuilderFactory.newPostBuilder();
-                                               postBuilder.copyPost(post).from(storedSone);
+                                               postBuilder.copyPost(post).from(storedSone.getId());
                                                Post newPost = postBuilder.build().setKnown(knownPosts.contains(post.getId()));
                                                if (!storedPosts.contains(newPost)) {
                                                        if (newPost.getTime() < getSoneFollowingTime(sone)) {
@@ -1136,7 +1136,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());
@@ -1313,9 +1313,9 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                                logger.log(Level.WARNING, "Invalid post found, aborting load!");
                                return;
                        }
-                       PostBuilder postBuilder = postBuilder().withId(postId).from(sone).withTime(postTime).withText(postText);
+                       PostBuilder postBuilder = postBuilder().withId(postId).from(sone.getId()).withTime(postTime).withText(postText);
                        if ((postRecipientId != null) && (postRecipientId.length() == 43)) {
-                               postBuilder.to(getSone(postRecipientId));
+                               postBuilder.to(postRecipientId);
                        }
                        posts.add(postBuilder.build());
                }
@@ -1336,7 +1336,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                                return;
                        }
                        PostReplyBuilder postReplyBuilder = postReplyBuilderFactory.newPostReplyBuilder();
-                       postReplyBuilder.withId(replyId).from(sone).to(postId).withTime(replyTime).withText(replyText);
+                       postReplyBuilder.withId(replyId).from(sone.getId()).to(postId).withTime(replyTime).withText(replyText);
                        replies.add(postReplyBuilder.build());
                }
 
@@ -1542,9 +1542,9 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                        return null;
                }
                PostBuilder postBuilder = postBuilderFactory.newPostBuilder();
-               postBuilder.from(sone).randomId().withTime(time).withText(text.trim());
+               postBuilder.from(sone.getId()).randomId().withTime(time).withText(text.trim());
                if (recipient != null) {
-                       postBuilder.to(recipient);
+                       postBuilder.to(recipient.getId());
                }
                final Post post = postBuilder.build();
                synchronized (posts) {
@@ -1669,7 +1669,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                        return null;
                }
                PostReplyBuilder postReplyBuilder = postReplyBuilderFactory.newPostReplyBuilder();
-               postReplyBuilder.randomId().from(sone).to(post.getId()).currentTime().withText(text.trim());
+               postReplyBuilder.randomId().from(sone.getId()).to(post.getId()).currentTime().withText(text.trim());
                final PostReply reply = postReplyBuilder.build();
                synchronized (replies) {
                        replies.put(reply.getId(), reply);
index cf85d03..388d804 100644 (file)
@@ -376,9 +376,9 @@ public class SoneDownloader extends AbstractService {
                                try {
                                        PostBuilder postBuilder = core.postBuilder();
                                        /* TODO - parse time correctly. */
-                                       postBuilder.withId(postId).from(sone).withTime(Long.parseLong(postTime)).withText(postText);
+                                       postBuilder.withId(postId).from(sone.getId()).withTime(Long.parseLong(postTime)).withText(postText);
                                        if ((postRecipientId != null) && (postRecipientId.length() == 43)) {
-                                               postBuilder.to(core.getSone(postRecipientId));
+                                               postBuilder.to(postRecipientId);
                                        }
                                        posts.add(postBuilder.build());
                                } catch (NumberFormatException nfe1) {
@@ -409,7 +409,7 @@ public class SoneDownloader extends AbstractService {
                                try {
                                        PostReplyBuilder postReplyBuilder = core.postReplyBuilder();
                                        /* TODO - parse time correctly. */
-                                       postReplyBuilder.withId(replyId).from(sone).to(replyPostId).withTime(Long.parseLong(replyTime)).withText(replyText);
+                                       postReplyBuilder.withId(replyId).from(sone.getId()).to(replyPostId).withTime(Long.parseLong(replyTime)).withText(replyText);
                                        replies.add(postReplyBuilder.build());
                                } catch (NumberFormatException nfe1) {
                                        /* TODO - mark Sone as bad. */
index 00f7354..87d02ee 100644 (file)
@@ -53,11 +53,11 @@ public interface PostBuilder {
        /**
         * Configures this builder to use the given Sone as sender of the new post.
         *
-        * @param sender
-        *            The sender of the post
+        * @param senderId
+        *            The ID of the sender of the post
         * @return This post builder
         */
-       public PostBuilder from(Sone sender);
+       public PostBuilder from(String senderId);
 
        /**
         * Configures this builder to use a random ID for the new post. If this
@@ -108,11 +108,11 @@ public interface PostBuilder {
         * Configures the builder to use the given {@link Sone} as recipient for the
         * post.
         *
-        * @param recipient
-        *            The recipient of the post
+        * @param recipientId
+        *            The ID of the recipient of the post
         * @return This post builder
         */
-       public PostBuilder to(Sone recipient);
+       public PostBuilder to(String recipientId);
 
        /**
         * Verifies this builder’s configuration and creates a new post.
@@ -122,14 +122,14 @@ public interface PostBuilder {
         * <ul>
         * <li>Exactly one of {@link #randomId()} or {@link #withId(String)} must
         * have been called.</li>
-        * <li>The {@link #from(Sone) sender} must not be {@code null}.</li>
+        * <li>The {@link #from(String) sender} must not be {@code null}.</li>
         * <li>Exactly one of {@link #currentTime()} or {@link #withTime(long)} must
         * have been called.</li>
         * <li>The {@link #withText(String) text} must not be {@code null} and must
         * contain something other than whitespace.</li>
-        * <li>The {@link #to(Sone) recipient} must either not have been set, or it
-        * must have been set to a {@link Sone} other than {@link #from(Sone) the
-        * sender}.</li>
+        * <li>The {@link #to(String) recipient} must either not have been set, or
+        * it must have been set to a {@link Sone} other than {@link #from(String)
+        * the sender}.</li>
         * </ul>
         *
         * @return A new post
index 1dc5f44..1e870b9 100644 (file)
@@ -54,13 +54,4 @@ public interface PostReply extends Reply<PostReply> {
         */
        public Optional<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 1ba7fd5..09eb98a 100644 (file)
@@ -42,7 +42,7 @@ public interface PostReplyBuilder extends ReplyBuilder<PostReplyBuilder> {
         * <ul>
         * <li>Exactly one of {@link #randomId()} or {@link #withId(String)} must
         * have been called.</li>
-        * <li>The {@link #from(Sone) sender} must not be {@code null}.</li>
+        * <li>The {@link #from(String) sender} must not be {@code null}.</li>
         * <li>Exactly one of {@link #currentTime()} or {@link #withTime(long)} must
         * have been called.</li>
         * <li>The {@link #withText(String) text} must not be {@code null} and must
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 53f3153..fa0aac8 100644 (file)
@@ -46,14 +46,14 @@ public interface ReplyBuilder<B extends ReplyBuilder<B>> {
        public B withId(String id);
 
        /**
-        * Configures this builder to use the given {@link Sone} as sender of the
-        * reply.
+        * Configures this builder to use the ID of the given {@link Sone} as sender
+        * of the reply.
         *
-        * @param sender
-        *            The sender of the reply
+        * @param senderId
+        *            The ID of the sender of the reply
         * @return This builder
         */
-       public B from(Sone sender);
+       public B from(String senderId);
 
        /**
         * Configures this builder to use the current time when creating the reply.
index e04e854..25dd1e1 100644 (file)
@@ -18,7 +18,6 @@
 package net.pterodactylus.sone.data.impl;
 
 import net.pterodactylus.sone.data.ReplyBuilder;
-import net.pterodactylus.sone.data.Sone;
 
 /**
  * Abstract implementation of a {@link ReplyBuilder}.
@@ -36,7 +35,7 @@ public class AbstractReplyBuilder<B extends ReplyBuilder<B>> implements ReplyBui
        protected String id;
 
        /** The sender of the reply. */
-       protected Sone sender;
+       protected String senderId;
 
        /** Whether to use the current time when creating the reply. */
        protected boolean currentTime;
@@ -72,8 +71,8 @@ public class AbstractReplyBuilder<B extends ReplyBuilder<B>> implements ReplyBui
         */
        @Override
        @SuppressWarnings("unchecked")
-       public B from(Sone sender) {
-               this.sender = sender;
+       public B from(String senderId) {
+               this.senderId = senderId;
                return (B) this;
        }
 
index 402b99a..25f6a86 100644 (file)
@@ -17,6 +17,7 @@
 
 package net.pterodactylus.sone.data.impl;
 
+import net.pterodactylus.sone.core.SoneProvider;
 import net.pterodactylus.sone.data.PostBuilder;
 import net.pterodactylus.sone.data.PostBuilderFactory;
 
@@ -28,12 +29,25 @@ import net.pterodactylus.sone.data.PostBuilderFactory;
  */
 public class DefaultPostBuilderFactory implements PostBuilderFactory {
 
+       /** The Sone provider. */
+       private final SoneProvider soneProvider;
+
+       /**
+        * Creates a new default post builder factory.
+        *
+        * @param soneProvider
+        *            The Sone provider
+        */
+       public DefaultPostBuilderFactory(SoneProvider soneProvider) {
+               this.soneProvider = soneProvider;
+       }
+
        /**
         * {@inheritDoc}
         */
        @Override
        public PostBuilder newPostBuilder() {
-               return new PostBuilderImpl();
+               return new PostBuilderImpl(soneProvider);
        }
 
 }
index 80bc3c7..5005e5e 100644 (file)
@@ -18,6 +18,7 @@
 package net.pterodactylus.sone.data.impl;
 
 import net.pterodactylus.sone.core.PostProvider;
+import net.pterodactylus.sone.core.SoneProvider;
 import net.pterodactylus.sone.data.PostReplyBuilder;
 import net.pterodactylus.sone.data.PostReplyBuilderFactory;
 
@@ -30,17 +31,23 @@ import com.google.inject.Inject;
  */
 public class DefaultPostReplyBuilderFactory implements PostReplyBuilderFactory {
 
+       /** The Sone provider. */
+       private final SoneProvider soneProvider;
+
        /** The post provider. */
        private final PostProvider postProvider;
 
        /**
         * Creates a new default post reply builder factory.
         *
+        * @param soneProvider
+        *            The Sone provider
         * @param postProvider
         *            The post provider
         */
        @Inject
-       public DefaultPostReplyBuilderFactory(PostProvider postProvider) {
+       public DefaultPostReplyBuilderFactory(SoneProvider soneProvider, PostProvider postProvider) {
+               this.soneProvider = soneProvider;
                this.postProvider = postProvider;
        }
 
@@ -49,7 +56,7 @@ public class DefaultPostReplyBuilderFactory implements PostReplyBuilderFactory {
         */
        @Override
        public PostReplyBuilder newPostReplyBuilder() {
-               return new PostReplyBuilderImpl(postProvider);
+               return new PostReplyBuilderImpl(soneProvider, postProvider);
        }
 
 }
index 967de9d..929f315 100644 (file)
@@ -21,9 +21,9 @@ import static com.google.common.base.Preconditions.checkState;
 
 import java.util.UUID;
 
+import net.pterodactylus.sone.core.SoneProvider;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostBuilder;
-import net.pterodactylus.sone.data.Sone;
 
 import org.apache.commons.lang.StringUtils;
 
@@ -34,6 +34,9 @@ import org.apache.commons.lang.StringUtils;
  */
 public class PostBuilderImpl implements PostBuilder {
 
+       /** The Sone provider for the created posts. */
+       private final SoneProvider soneProvider;
+
        /** Wether to create a post with a random ID. */
        private boolean randomId;
 
@@ -41,7 +44,7 @@ public class PostBuilderImpl implements PostBuilder {
        private String id;
 
        /** The sender of the post. */
-       private Sone sender;
+       private String senderId;
 
        /** Whether to use the current time when creating the post. */
        private boolean currentTime;
@@ -53,7 +56,17 @@ public class PostBuilderImpl implements PostBuilder {
        private String text;
 
        /** The (optional) recipient of the post. */
-       private Sone recipient;
+       private String recipientId;
+
+       /**
+        * Creates a new post builder.
+        *
+        * @param soneProvider
+        *            The Sone provider
+        */
+       public PostBuilderImpl(SoneProvider soneProvider) {
+               this.soneProvider = soneProvider;
+       }
 
        /**
         * {@inheritDoc}
@@ -62,11 +75,11 @@ public class PostBuilderImpl implements PostBuilder {
        public PostBuilder copyPost(Post post) {
                this.randomId = false;
                this.id = post.getId();
-               this.sender = post.getSone();
+               this.senderId = post.getSone().getId();
                this.currentTime = false;
                this.time = post.getTime();
                this.text = post.getText();
-               this.recipient = post.getRecipient();
+               this.recipientId = (post.getRecipient() != null) ? post.getRecipient().getId() : null;
                return this;
        }
 
@@ -92,8 +105,8 @@ public class PostBuilderImpl implements PostBuilder {
         * {@inheritDoc}
         */
        @Override
-       public PostBuilder from(Sone sender) {
-               this.sender = sender;
+       public PostBuilder from(String senderId) {
+               this.senderId = senderId;
                return this;
        }
 
@@ -128,8 +141,8 @@ public class PostBuilderImpl implements PostBuilder {
         * {@inheritDoc}
         */
        @Override
-       public PostBuilder to(Sone recipient) {
-               this.recipient = recipient;
+       public PostBuilder to(String recipientId) {
+               this.recipientId = recipientId;
                return this;
        }
 
@@ -139,11 +152,11 @@ public class PostBuilderImpl implements PostBuilder {
        @Override
        public Post build() {
                checkState((randomId && (id == null)) || (!randomId && (id != null)), "exactly one of random ID or custom ID must be set");
-               checkState(sender != null, "sender must not be null");
+               checkState(senderId != null, "sender must not be null");
                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);
+               checkState((recipientId == null) || !recipientId.equals(senderId), "sender and recipient must not be the same");
+               return new PostImpl(soneProvider, randomId ? UUID.randomUUID().toString() : id, senderId, recipientId, currentTime ? System.currentTimeMillis() : time, text);
        }
 
 }
index 2cc0b00..bb8a4df 100644 (file)
@@ -19,6 +19,7 @@ package net.pterodactylus.sone.data.impl;
 
 import java.util.UUID;
 
+import net.pterodactylus.sone.core.SoneProvider;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Sone;
 
@@ -30,20 +31,23 @@ import net.pterodactylus.sone.data.Sone;
  */
 public class PostImpl implements Post {
 
+       /** The Sone provider. */
+       private final SoneProvider soneProvider;
+
        /** The GUID of the post. */
        private final UUID id;
 
-       /** The Sone this post belongs to. */
-       private volatile Sone sone;
+       /** The ID of the owning Sone. */
+       private final String soneId;
 
-       /** The Sone of the recipient. */
-       private volatile Sone recipient;
+       /** The ID of the recipient Sone. */
+       private final String recipientId;
 
        /** 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;
@@ -51,54 +55,24 @@ public class PostImpl implements Post {
        /**
         * Creates a new post.
         *
+        * @param soneProvider
+        *            The Sone provider
         * @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 soneId
+        *            The ID of the Sone this post belongs to
+        * @param recipientId
+        *            The ID of 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(SoneProvider soneProvider, String id, String soneId, String recipientId, long time, String text) {
+               this.soneProvider = soneProvider;
                this.id = UUID.fromString(id);
-               this.sone = sone;
+               this.soneId = soneId;
+               this.recipientId = recipientId;
                this.time = time;
                this.text = text;
        }
@@ -120,19 +94,7 @@ public class PostImpl implements Post {
         */
        @Override
        public Sone getSone() {
-               return sone;
-       }
-
-       /**
-        * 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;
+               return soneProvider.getSone(soneId, false);
        }
 
        /**
@@ -140,21 +102,7 @@ public class PostImpl implements Post {
         */
        @Override
        public Sone getRecipient() {
-               return recipient;
-       }
-
-       /**
-        * 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;
+               return soneProvider.getSone(recipientId, false);
        }
 
        /**
@@ -166,18 +114,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 +122,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
@@ -243,7 +167,7 @@ public class PostImpl implements Post {
         */
        @Override
        public String toString() {
-               return getClass().getName() + "[id=" + id + ",sone=" + sone + ",time=" + time + ",text=" + text + "]";
+               return String.format("%s[id=%s,sone=%s,recipient=%s,time=%d,text=%s]", getClass().getName(), id, soneId, recipientId, time, text);
        }
 
 }
index 18ce200..1709b6e 100644 (file)
@@ -22,6 +22,7 @@ import static com.google.common.base.Preconditions.checkState;
 import java.util.UUID;
 
 import net.pterodactylus.sone.core.PostProvider;
+import net.pterodactylus.sone.core.SoneProvider;
 import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.PostReplyBuilder;
 
@@ -35,7 +36,10 @@ import org.apache.commons.lang.StringUtils;
  */
 public class PostReplyBuilderImpl extends AbstractReplyBuilder<PostReplyBuilder> implements PostReplyBuilder {
 
-       /** The post builder. */
+       /** The Sone provider. */
+       private final SoneProvider soneProvider;
+
+       /** The post provider. */
        private final PostProvider postProvider;
 
        /** The ID of the post the created reply refers to. */
@@ -44,10 +48,13 @@ public class PostReplyBuilderImpl extends AbstractReplyBuilder<PostReplyBuilder>
        /**
         * Creates a new post reply builder.
         *
+        * @param soneProvider
+        *            The Sone provider
         * @param postProvider
         *            The post provider
         */
-       public PostReplyBuilderImpl(PostProvider postProvider) {
+       public PostReplyBuilderImpl(SoneProvider soneProvider, PostProvider postProvider) {
+               this.soneProvider = soneProvider;
                this.postProvider = postProvider;
        }
 
@@ -66,17 +73,12 @@ public class PostReplyBuilderImpl extends AbstractReplyBuilder<PostReplyBuilder>
        @Override
        public PostReply build() {
                checkState((randomId && (id == null)) || (!randomId && (id != null)), "either random ID nor custom ID must be set");
-               checkState(sender != null, "sender must not be null");
+               checkState(senderId != null, "sender must not be null");
                checkState((currentTime && (time == 0)) || (!currentTime && (time >= 0)), "either current time or custom time must be set");
                checkState(!StringUtils.isBlank(text), "text must not be empty");
                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(soneProvider, postProvider, randomId ? UUID.randomUUID().toString() : id, senderId, currentTime ? System.currentTimeMillis() : time, text, postId);
        }
 }
index fdedaa0..065ce2f 100644 (file)
@@ -18,6 +18,7 @@
 package net.pterodactylus.sone.data.impl;
 
 import net.pterodactylus.sone.core.PostProvider;
+import net.pterodactylus.sone.core.SoneProvider;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
 
@@ -34,18 +35,28 @@ 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.
         *
+        * @param soneProvider
+        *            The Sone provider
         * @param postProvider
         *            The post provider
         * @param id
         *            The ID of the reply
+        * @param soneId
+        *            The ID of 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(SoneProvider soneProvider, PostProvider postProvider, String id, String soneId, long time, String text, String postId) {
+               super(soneProvider, id, soneId, time, text);
                this.postProvider = postProvider;
                this.postId = postId;
        }
@@ -70,17 +81,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..5590c7e 100644 (file)
@@ -17,8 +17,7 @@
 
 package net.pterodactylus.sone.data.impl;
 
-import java.util.UUID;
-
+import net.pterodactylus.sone.core.SoneProvider;
 import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.Sone;
 
@@ -31,60 +30,42 @@ import net.pterodactylus.sone.data.Sone;
  */
 public abstract class ReplyImpl<T extends Reply<T>> implements Reply<T> {
 
+       /** The Sone provider. */
+       private final SoneProvider soneProvider;
+
        /** The ID of the reply. */
        private final String id;
 
        /** The Sone that created this reply. */
-       private volatile Sone sone;
+       private final String soneId;
 
        /** 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 soneProvider
+        *            The Sone provider
         * @param id
         *            The ID of the reply
-        * @param sone
-        *            The Sone of the reply
+        * @param soneId
+        *            The ID of the Sone of the reply
         * @param time
         *            The time of the reply
         * @param text
         *            The text of the reply
         */
-       protected ReplyImpl(String id, Sone sone, long time, String text) {
+       protected ReplyImpl(SoneProvider soneProvider, String id, String soneId, long time, String text) {
+               this.soneProvider = soneProvider;
                this.id = id;
-               this.sone = sone;
+               this.soneId = soneId;
                this.time = time;
                this.text = text;
        }
@@ -102,21 +83,7 @@ public abstract class ReplyImpl<T extends Reply<T>> implements Reply<T> {
         */
        @Override
        public Sone getSone() {
-               return sone;
-       }
-
-       /**
-        * 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;
+               return soneProvider.getSone(soneId, false);
        }
 
        /**
@@ -128,20 +95,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 +103,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
@@ -210,7 +149,7 @@ public abstract class ReplyImpl<T extends Reply<T>> implements Reply<T> {
         */
        @Override
        public String toString() {
-               return getClass().getName() + "[id=" + id + ",sone=" + sone + ",time=" + time + ",text=" + text + "]";
+               return String.format("%s[id=%s,sone=%s,time=%d,text=%s]", getClass().getName(), id, soneId, time, text);
        }
 
 }
index eb2e434..4b0f3eb 100644 (file)
@@ -25,6 +25,7 @@ import java.util.logging.Logger;
 import net.pterodactylus.sone.core.Core;
 import net.pterodactylus.sone.core.FreenetInterface;
 import net.pterodactylus.sone.core.PostProvider;
+import net.pterodactylus.sone.core.SoneProvider;
 import net.pterodactylus.sone.core.WebOfTrustUpdater;
 import net.pterodactylus.sone.data.PostBuilderFactory;
 import net.pterodactylus.sone.data.PostReplyBuilderFactory;
@@ -225,6 +226,7 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr
                                bind(FcpInterface.class).in(Singleton.class);
                                bind(PostBuilderFactory.class).to(DefaultPostBuilderFactory.class).in(Singleton.class);
                                bind(PostReplyBuilderFactory.class).to(DefaultPostReplyBuilderFactory.class).in(Singleton.class);
+                               bind(SoneProvider.class).to(Core.class).in(Singleton.class);
                                bind(PostProvider.class).to(Core.class).in(Singleton.class);
                                bindListener(Matchers.any(), new TypeListener() {