Only store the post ID in the reply.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 22 Jan 2013 08:38:18 +0000 (09:38 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 22 Jan 2013 08:38:18 +0000 (09:38 +0100)
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/PostReply.java
src/main/java/net/pterodactylus/sone/data/PostReplyBuilder.java
src/main/java/net/pterodactylus/sone/data/impl/DefaultPostReplyBuilderFactory.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/main/SonePlugin.java

index ca4e16b..8172b45 100644 (file)
@@ -1330,7 +1330,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                                return;
                        }
                        PostReplyBuilder postReplyBuilder = postReplyBuilderFactory.newPostReplyBuilder();
-                       postReplyBuilder.withId(replyId).from(sone).to(getPost(postId)).withTime(replyTime).withText(replyText);
+                       postReplyBuilder.withId(replyId).from(sone).to(postId).withTime(replyTime).withText(replyText);
                        replies.add(postReplyBuilder.build());
                }
 
@@ -1663,7 +1663,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                        return null;
                }
                PostReplyBuilder postReplyBuilder = postReplyBuilderFactory.newPostReplyBuilder();
-               postReplyBuilder.randomId().from(sone).to(post).currentTime().withText(text.trim());
+               postReplyBuilder.randomId().from(sone).to(post.getId()).currentTime().withText(text.trim());
                final PostReply reply = postReplyBuilder.build();
                synchronized (replies) {
                        replies.put(reply.getId(), reply);
index 51bc6fd..cf85d03 100644 (file)
@@ -409,7 +409,7 @@ public class SoneDownloader extends AbstractService {
                                try {
                                        PostReplyBuilder postReplyBuilder = core.postReplyBuilder();
                                        /* TODO - parse time correctly. */
-                                       postReplyBuilder.withId(replyId).from(sone).to(core.getPost(replyPostId)).withTime(Long.parseLong(replyTime)).withText(replyText);
+                                       postReplyBuilder.withId(replyId).from(sone).to(replyPostId).withTime(Long.parseLong(replyTime)).withText(replyText);
                                        replies.add(postReplyBuilder.build());
                                } catch (NumberFormatException nfe1) {
                                        /* TODO - mark Sone as bad. */
index a4d9ef3..4452e2e 100644 (file)
@@ -35,10 +35,10 @@ public interface PostReply extends Reply<PostReply> {
        /**
         * Sets the post this reply refers to.
         *
-        * @param post
-        *            The post this reply refers to
+        * @param postId
+        *            The ID of the post to reply to
         * @return This reply
         */
-       public PostReply setPost(Post post);
+       public PostReply setPost(String postId);
 
 }
index 6c3e236..1ba7fd5 100644 (file)
@@ -28,11 +28,11 @@ public interface PostReplyBuilder extends ReplyBuilder<PostReplyBuilder> {
         * Configures this builder to set the given post as post the created reply
         * refers to.
         *
-        * @param post
-        *            The post the reply refers to
+        * @param postId
+        *            The ID of the post the reply refers to
         * @return This builder
         */
-       public PostReplyBuilder to(Post post);
+       public PostReplyBuilder to(String postId);
 
        /**
         * Verifies the configuration of this builder and creates a new post reply.
@@ -47,7 +47,7 @@ public interface PostReplyBuilder extends ReplyBuilder<PostReplyBuilder> {
         * 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(Post) post} have been set.</li>
+        * <li>The {@link #to(String) post} have been set.</li>
         * </ul>
         *
         * @return The created post reply
index efe3c30..80bc3c7 100644 (file)
 
 package net.pterodactylus.sone.data.impl;
 
+import net.pterodactylus.sone.core.PostProvider;
 import net.pterodactylus.sone.data.PostReplyBuilder;
 import net.pterodactylus.sone.data.PostReplyBuilderFactory;
 
+import com.google.inject.Inject;
+
 /**
  * {@link PostReplyBuilderFactory} that creates {@link PostReplyBuilderImpl}s.
  *
@@ -27,12 +30,26 @@ import net.pterodactylus.sone.data.PostReplyBuilderFactory;
  */
 public class DefaultPostReplyBuilderFactory implements PostReplyBuilderFactory {
 
+       /** The post provider. */
+       private final PostProvider postProvider;
+
+       /**
+        * Creates a new default post reply builder factory.
+        *
+        * @param postProvider
+        *            The post provider
+        */
+       @Inject
+       public DefaultPostReplyBuilderFactory(PostProvider postProvider) {
+               this.postProvider = postProvider;
+       }
+
        /**
         * {@inheritDoc}
         */
        @Override
        public PostReplyBuilder newPostReplyBuilder() {
-               return new PostReplyBuilderImpl();
+               return new PostReplyBuilderImpl(postProvider);
        }
 
 }
index 35b87e8..18ce200 100644 (file)
@@ -21,7 +21,7 @@ import static com.google.common.base.Preconditions.checkState;
 
 import java.util.UUID;
 
-import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.core.PostProvider;
 import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.PostReplyBuilder;
 
@@ -35,15 +35,28 @@ import org.apache.commons.lang.StringUtils;
  */
 public class PostReplyBuilderImpl extends AbstractReplyBuilder<PostReplyBuilder> implements PostReplyBuilder {
 
-       /** The post the created reply refers to. */
-       private Post post;
+       /** The post builder. */
+       private final PostProvider postProvider;
+
+       /** The ID of the post the created reply refers to. */
+       private String postId;
+
+       /**
+        * Creates a new post reply builder.
+        *
+        * @param postProvider
+        *            The post provider
+        */
+       public PostReplyBuilderImpl(PostProvider postProvider) {
+               this.postProvider = postProvider;
+       }
 
        /**
         * {@inheritDoc}
         */
        @Override
-       public PostReplyBuilder to(Post post) {
-               this.post = post;
+       public PostReplyBuilder to(String postId) {
+               this.postId = postId;
                return this;
        }
 
@@ -56,12 +69,12 @@ public class PostReplyBuilderImpl extends AbstractReplyBuilder<PostReplyBuilder>
                checkState(sender != 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(post != null, "post must not be null");
+               checkState(postId != null, "post must not be null");
 
                /* create new post reply. */
-               PostReplyImpl postReplyImpl = new PostReplyImpl(randomId ? UUID.randomUUID().toString() : id);
+               PostReplyImpl postReplyImpl = new PostReplyImpl(postProvider, randomId ? UUID.randomUUID().toString() : id);
                postReplyImpl.setSone(sender);
-               postReplyImpl.setPost(post);
+               postReplyImpl.setPost(postId);
                postReplyImpl.setTime(currentTime ? System.currentTimeMillis() : time);
                postReplyImpl.setText(text);
                return postReplyImpl;
index 0e66a8f..361a2e9 100644 (file)
 
 package net.pterodactylus.sone.data.impl;
 
-import java.util.UUID;
-
+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.
@@ -30,66 +28,24 @@ import net.pterodactylus.sone.data.Sone;
  */
 public class PostReplyImpl extends ReplyImpl<PostReply> implements PostReply {
 
-       /** The Post this reply refers to. */
-       private volatile Post post;
+       /** The post provider. */
+       private final PostProvider postProvider;
 
-       /**
-        * Creates a new reply.
-        *
-        * @param id
-        *            The ID of the reply
-        */
-       public PostReplyImpl(String id) {
-               this(id, null, null, 0, null);
-       }
+       /** The Post this reply refers to. */
+       private volatile String postId;
 
        /**
         * Creates a new reply.
         *
-        * @param sone
-        *            The sone that posted the reply
-        * @param post
-        *            The post to reply to
-        * @param text
-        *            The text of the reply
-        */
-       public PostReplyImpl(Sone sone, Post post, String text) {
-               this(sone, post, System.currentTimeMillis(), text);
-       }
-
-       /**
-        * Creates a new reply-
-        *
-        * @param sone
-        *            The sone that posted the reply
-        * @param post
-        *            The post to reply to
-        * @param time
-        *            The time of the reply
-        * @param text
-        *            The text of the reply
-        */
-       public PostReplyImpl(Sone sone, Post post, long time, String text) {
-               this(UUID.randomUUID().toString(), sone, post, time, text);
-       }
-
-       /**
-        * Creates a new reply-
-        *
-        * @param sone
-        *            The sone that posted the reply
+        * @param postProvider
+        *            The post provider
         * @param id
         *            The ID of the reply
-        * @param post
-        *            The post to reply to
-        * @param time
-        *            The time of the reply
-        * @param text
-        *            The text of the reply
         */
-       public PostReplyImpl(String id, Sone sone, Post post, long time, String text) {
-               super(id, sone, time, text);
-               this.post = post;
+       public PostReplyImpl(PostProvider postProvider, String id) {
+               super(id);
+               this.postProvider = postProvider;
+               this.postId = postId;
        }
 
        //
@@ -101,19 +57,19 @@ public class PostReplyImpl extends ReplyImpl<PostReply> implements PostReply {
         */
        @Override
        public Post getPost() {
-               return post;
+               return postProvider.getPost(postId);
        }
 
        /**
         * Sets the post this reply refers to.
         *
-        * @param post
-        *            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(Post post) {
-               this.post = post;
+       public PostReply setPost(String postId) {
+               this.postId = postId;
                return this;
        }
 
index 152a70f..1114c42 100644 (file)
@@ -24,6 +24,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.WebOfTrustUpdater;
 import net.pterodactylus.sone.data.PostBuilderFactory;
 import net.pterodactylus.sone.data.PostReplyBuilderFactory;
@@ -223,6 +224,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(PostProvider.class).to(Core.class).in(Singleton.class);
                                bindListener(Matchers.any(), new TypeListener() {
 
                                        @Override