Merge commit '0.3.1-RC2' into next
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index 096f192..54908d8 100644 (file)
@@ -572,16 +572,33 @@ public class Core implements IdentityListener {
        }
 
        /**
-        * Returns the reply with the given ID.
+        * Returns the reply with the given ID. If there is no reply with the given
+        * ID yet, a new one is created.
         *
         * @param replyId
         *            The ID of the reply to get
-        * @return The reply, or {@code null} if there is no such reply
+        * @return The reply
         */
        public Reply getReply(String replyId) {
+               return getReply(replyId, true);
+       }
+
+       /**
+        * Returns the reply with the given ID. If there is no reply with the given
+        * ID yet, a new one is created, unless {@code create} is false in which
+        * case {@code null} is returned.
+        *
+        * @param replyId
+        *            The ID of the reply to get
+        * @param create
+        *            {@code true} to always return a {@link Reply}, {@code false}
+        *            to return {@code null} if no reply can be found
+        * @return The reply, or {@code null} if there is no such reply
+        */
+       public Reply getReply(String replyId, boolean create) {
                synchronized (replies) {
                        Reply reply = replies.get(replyId);
-                       if (reply == null) {
+                       if (create && (reply == null)) {
                                reply = new Reply(replyId);
                                replies.put(replyId, reply);
                        }
@@ -1226,21 +1243,6 @@ public class Core implements IdentityListener {
        }
 
        /**
-        * Creates a new reply.
-        *
-        * @param sone
-        *            The Sone that creates the reply
-        * @param post
-        *            The post that this reply refers to
-        * @param text
-        *            The text of the reply
-        * @return The created reply
-        */
-       public Reply createReply(Sone sone, Post post, String text) {
-               return createReply(sone, post, System.currentTimeMillis(), text);
-       }
-
-       /**
         * Marks the given post as known, if it is currently a new post (according
         * to {@link #isNewPost(String)}).
         *
@@ -1263,6 +1265,21 @@ public class Core implements IdentityListener {
         *            The Sone that creates the reply
         * @param post
         *            The post that this reply refers to
+        * @param text
+        *            The text of the reply
+        * @return The created reply
+        */
+       public Reply createReply(Sone sone, Post post, String text) {
+               return createReply(sone, post, System.currentTimeMillis(), text);
+       }
+
+       /**
+        * Creates a new reply.
+        *
+        * @param sone
+        *            The Sone that creates the reply
+        * @param post
+        *            The post that this reply refers to
         * @param time
         *            The time of the reply
         * @param text