Add method to expose a Post loader.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 4 Nov 2013 05:27:03 +0000 (06:27 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:51 +0000 (22:25 +0100)
src/main/java/net/pterodactylus/sone/database/PostDatabase.java
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java

index 7bfa33a..9480071 100644 (file)
@@ -22,6 +22,7 @@ import java.util.Collection;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Sone;
 
+import com.google.common.base.Function;
 import com.google.common.base.Optional;
 
 /**
@@ -31,6 +32,8 @@ import com.google.common.base.Optional;
  */
 public interface PostDatabase {
 
+       Function<String, Optional<Post>> getPost();
+
        /**
         * Returns the post with the given ID.
         *
index 02ca290..8343caf 100644 (file)
@@ -244,6 +244,16 @@ public class MemoryDatabase extends AbstractService implements Database {
        //
 
        @Override
+       public Function<String, Optional<Post>> getPost() {
+               return new Function<String, Optional<Post>>() {
+                       @Override
+                       public Optional<Post> apply(String postId) {
+                               return (postId == null) ? Optional.<Post>absent() : getPost(postId);
+                       }
+               };
+       }
+
+       @Override
        public Optional<Post> getPost(String postId) {
                lock.readLock().lock();
                try {