Use database instead of separate providers.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 15 Oct 2013 05:26:30 +0000 (07:26 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:26 +0000 (22:25 +0100)
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/data/impl/ReplyImpl.java

index e326304..2c303a1 100644 (file)
 
 package net.pterodactylus.sone.data.impl;
 
-import net.pterodactylus.sone.database.PostProvider;
+import net.pterodactylus.sone.database.Database;
 import net.pterodactylus.sone.database.PostReplyBuilder;
 import net.pterodactylus.sone.database.PostReplyBuilderFactory;
-import net.pterodactylus.sone.database.SoneProvider;
 
 import com.google.inject.Inject;
 
@@ -31,24 +30,11 @@ import com.google.inject.Inject;
  */
 public class DefaultPostReplyBuilderFactory implements PostReplyBuilderFactory {
 
-       /** The Sone provider. */
-       private final SoneProvider soneProvider;
+       private final Database database;
 
-       /** 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(SoneProvider soneProvider, PostProvider postProvider) {
-               this.soneProvider = soneProvider;
-               this.postProvider = postProvider;
+       public DefaultPostReplyBuilderFactory(Database database) {
+               this.database = database;
        }
 
        /**
@@ -56,7 +42,7 @@ public class DefaultPostReplyBuilderFactory implements PostReplyBuilderFactory {
         */
        @Override
        public PostReplyBuilder newPostReplyBuilder() {
-               return new PostReplyBuilderImpl(soneProvider, postProvider);
+               return new PostReplyBuilderImpl(database);
        }
 
 }
index dac84ad..4b43aa7 100644 (file)
@@ -22,9 +22,8 @@ import static com.google.common.base.Preconditions.checkState;
 import java.util.UUID;
 
 import net.pterodactylus.sone.data.PostReply;
-import net.pterodactylus.sone.database.PostProvider;
+import net.pterodactylus.sone.database.Database;
 import net.pterodactylus.sone.database.PostReplyBuilder;
-import net.pterodactylus.sone.database.SoneProvider;
 
 import org.apache.commons.lang.StringUtils;
 
@@ -36,23 +35,10 @@ import org.apache.commons.lang.StringUtils;
  */
 public class PostReplyBuilderImpl extends AbstractPostReplyBuilder {
 
-       /** The Sone provider. */
-       private final SoneProvider soneProvider;
+       private final Database database;
 
-       /** The post provider. */
-       private final PostProvider postProvider;
-
-       /**
-        * Creates a new post reply builder.
-        *
-        * @param soneProvider
-        *            The Sone provider
-        * @param postProvider
-        *            The post provider
-        */
-       public PostReplyBuilderImpl(SoneProvider soneProvider, PostProvider postProvider) {
-               this.soneProvider = soneProvider;
-               this.postProvider = postProvider;
+       public PostReplyBuilderImpl(Database database) {
+               this.database = database;
        }
 
        /**
@@ -67,7 +53,7 @@ public class PostReplyBuilderImpl extends AbstractPostReplyBuilder {
                checkState(postId != null, "post must not be null");
 
                /* create new post reply. */
-               return new PostReplyImpl(soneProvider, postProvider, randomId ? UUID.randomUUID().toString() : id, senderId, currentTime ? System.currentTimeMillis() : time, text, postId);
+               return new PostReplyImpl(database, randomId ? UUID.randomUUID().toString() : id, senderId, currentTime ? System.currentTimeMillis() : time, text, postId);
        }
 
 }
index 30badf7..c1a2423 100644 (file)
@@ -19,8 +19,7 @@ package net.pterodactylus.sone.data.impl;
 
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
-import net.pterodactylus.sone.database.PostProvider;
-import net.pterodactylus.sone.database.SoneProvider;
+import net.pterodactylus.sone.database.Database;
 
 import com.google.common.base.Optional;
 
@@ -31,33 +30,26 @@ import com.google.common.base.Optional;
  */
 public class PostReplyImpl extends ReplyImpl<PostReply> implements PostReply {
 
-       /** The post provider. */
-       private final PostProvider postProvider;
-
        /** The Post this reply refers to. */
        private final String postId;
 
        /**
         * Creates a new reply.
         *
-        * @param soneProvider
-        *            The Sone provider
-        * @param postProvider
-        *            The post provider
+        * @param database
+        *              The database
         * @param id
-        *            The ID of the reply
+        *              The ID of the reply
         * @param soneId
-        *            The ID of the Sone of the reply
+        *              The ID of the Sone of the reply
         * @param time
-        *            The time of the reply
+        *              The time of the reply
         * @param text
-        *            The text of the reply
+        *              The text of the reply
         * @param postId
-        *            The ID of the post this reply refers to
         */
-       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;
+       public PostReplyImpl(Database database, String id, String soneId, long time, String text, String postId) {
+               super(database, id, soneId, time, text);
                this.postId = postId;
        }
 
@@ -65,20 +57,16 @@ public class PostReplyImpl extends ReplyImpl<PostReply> implements PostReply {
        // ACCESSORS
        //
 
-       /**
-        * {@inheritDocs}
-        */
+       /** {@inheritDocs} */
        @Override
        public String getPostId() {
                return postId;
        }
 
-       /**
-        * {@inheritDoc}
-        */
+       /** {@inheritDoc} */
        @Override
        public Optional<Post> getPost() {
-               return postProvider.getPost(postId);
+               return database.getPost(postId);
        }
 
 }
index a67081f..fae5436 100644 (file)
@@ -19,19 +19,18 @@ package net.pterodactylus.sone.data.impl;
 
 import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.database.SoneProvider;
+import net.pterodactylus.sone.database.Database;
 
 /**
  * Abstract base class for all replies.
  *
  * @param <T>
- *            The type of the reply
+ *             The type of the reply
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
 public abstract class ReplyImpl<T extends Reply<T>> implements Reply<T> {
 
-       /** The Sone provider. */
-       private final SoneProvider soneProvider;
+       protected final Database database;
 
        /** The ID of the reply. */
        private final String id;
@@ -51,68 +50,55 @@ public abstract class ReplyImpl<T extends Reply<T>> implements Reply<T> {
        /**
         * Creates a new reply.
         *
-        * @param soneProvider
-        *            The Sone provider
+        * @param database
+        *              The database
         * @param id
-        *            The ID of the reply
+        *              The ID of the reply
         * @param soneId
-        *            The ID of the Sone of the reply
+        *              The ID of the Sone of the reply
         * @param time
-        *            The time of the reply
+        *              The time of the reply
         * @param text
-        *            The text of the reply
         */
-       protected ReplyImpl(SoneProvider soneProvider, String id, String soneId, long time, String text) {
-               this.soneProvider = soneProvider;
+       protected ReplyImpl(Database database, String id, String soneId, long time, String text) {
+               this.database = database;
                this.id = id;
                this.soneId = soneId;
                this.time = time;
                this.text = text;
        }
 
-       /**
-        * {@inheritDoc}
-        */
+       /** {@inheritDoc} */
        @Override
        public String getId() {
                return id;
        }
 
-       /**
-        * {@inheritDoc}
-        */
+       /** {@inheritDoc} */
        @Override
        public Sone getSone() {
-               return soneProvider.getSone(soneId).get();
+               return database.getSone(soneId).get();
        }
 
-       /**
-        * {@inheritDoc}
-        */
+       /** {@inheritDoc} */
        @Override
        public long getTime() {
                return time;
        }
 
-       /**
-        * {@inheritDoc}
-        */
+       /** {@inheritDoc} */
        @Override
        public String getText() {
                return text;
        }
 
-       /**
-        * {@inheritDoc}
-        */
+       /** {@inheritDoc} */
        @Override
        public boolean isKnown() {
                return known;
        }
 
-       /**
-        * {@inheritDoc}
-        */
+       /** {@inheritDoc} */
        @Override
        @SuppressWarnings("unchecked")
        public T setKnown(boolean known) {
@@ -124,17 +110,13 @@ public abstract class ReplyImpl<T extends Reply<T>> implements Reply<T> {
        // OBJECT METHODS
        //
 
-       /**
-        * {@inheritDoc}
-        */
+       /** {@inheritDoc} */
        @Override
        public int hashCode() {
                return id.hashCode();
        }
 
-       /**
-        * {@inheritDoc}
-        */
+       /** {@inheritDoc} */
        @Override
        public boolean equals(Object object) {
                if (!(object instanceof Reply<?>)) {
@@ -144,9 +126,7 @@ public abstract class ReplyImpl<T extends Reply<T>> implements Reply<T> {
                return reply.getId().equals(id);
        }
 
-       /**
-        * {@inheritDoc}
-        */
+       /** {@inheritDoc} */
        @Override
        public String toString() {
                return String.format("%s[id=%s,sone=%s,time=%d,text=%s]", getClass().getName(), id, soneId, time, text);