Add method to not create a new post automatically.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 17 Nov 2010 21:08:44 +0000 (22:08 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 17 Nov 2010 21:08:44 +0000 (22:08 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java

index 806ac21..ea491bb 100644 (file)
@@ -495,9 +495,23 @@ public class Core implements IdentityListener {
         * @return The post, or {@code null} if there is no such post
         */
        public Post getPost(String postId) {
+               return getPost(postId, true);
+       }
+
+       /**
+        * Returns the post with the given ID, optionally creating a new post.
+        *
+        * @param postId
+        *            The ID of the post to get
+        * @param create
+        *            {@code true} it create a new post if no post with the given ID
+        *            exists, {@code false} to return {@code null}
+        * @return The post, or {@code null} if there is no such post
+        */
+       public Post getPost(String postId, boolean create) {
                synchronized (posts) {
                        Post post = posts.get(postId);
-                       if (post == null) {
+                       if ((post == null) && create) {
                                post = new Post(postId);
                                posts.put(postId, post);
                        }