Remove randomId() and currentTime() methods from ReplyBuilder.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / impl / ReplyImpl.java
index ee8c01e..fae5436 100644 (file)
@@ -19,21 +19,24 @@ package net.pterodactylus.sone.data.impl;
 
 import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.Sone;
+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> {
 
+       protected final Database database;
+
        /** The ID of the reply. */
        private final String id;
 
        /** The Sone that created this reply. */
-       private final Sone sone;
+       private final String soneId;
 
        /** The time of the reply. */
        private final long time;
@@ -47,65 +50,55 @@ public abstract class ReplyImpl<T extends Reply<T>> implements Reply<T> {
        /**
         * Creates a new reply.
         *
+        * @param database
+        *              The database
         * @param id
-        *            The ID of the reply
-        * @param sone
-        *            The Sone of the reply
+        *              The ID of the reply
+        * @param soneId
+        *              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(String id, Sone sone, long time, String text) {
+       protected ReplyImpl(Database database, String id, String soneId, long time, String text) {
+               this.database = database;
                this.id = id;
-               this.sone = sone;
+               this.soneId = soneId;
                this.time = time;
                this.text = text;
        }
 
-       /**
-        * {@inheritDoc}
-        */
+       /** {@inheritDoc} */
        @Override
        public String getId() {
                return id;
        }
 
-       /**
-        * {@inheritDoc}
-        */
+       /** {@inheritDoc} */
        @Override
        public Sone getSone() {
-               return sone;
+               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) {
@@ -117,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<?>)) {
@@ -137,12 +126,10 @@ public abstract class ReplyImpl<T extends Reply<T>> implements Reply<T> {
                return reply.getId().equals(id);
        }
 
-       /**
-        * {@inheritDoc}
-        */
+       /** {@inheritDoc} */
        @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);
        }
 
 }