From 1b53b3ea48254d51bfe8c9389066fc9628efab4b Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 4 Nov 2013 06:27:03 +0100 Subject: [PATCH] Add method to expose a Post loader. --- .../java/net/pterodactylus/sone/database/PostDatabase.java | 3 +++ .../net/pterodactylus/sone/database/memory/MemoryDatabase.java | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/database/PostDatabase.java b/src/main/java/net/pterodactylus/sone/database/PostDatabase.java index 7bfa33a..9480071 100644 --- a/src/main/java/net/pterodactylus/sone/database/PostDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/PostDatabase.java @@ -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> getPost(); + /** * Returns the post with the given ID. * diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java index 02ca290..8343caf 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -244,6 +244,16 @@ public class MemoryDatabase extends AbstractService implements Database { // @Override + public Function> getPost() { + return new Function>() { + @Override + public Optional apply(String postId) { + return (postId == null) ? Optional.absent() : getPost(postId); + } + }; + } + + @Override public Optional getPost(String postId) { lock.readLock().lock(); try { -- 2.7.4