From 0b8194c25d3dc9a68601b95e13adc4a5d92628c1 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:26:47 +0100 Subject: [PATCH] Add method to expose a Sone loader. --- src/main/java/net/pterodactylus/sone/core/Core.java | 6 ++++++ .../java/net/pterodactylus/sone/database/SoneProvider.java | 3 +++ .../net/pterodactylus/sone/database/memory/MemoryDatabase.java | 10 ++++++++++ 3 files changed, 19 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 8fcfe10..8e6f1b0 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -97,6 +97,7 @@ import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.service.AbstractService; import net.pterodactylus.util.thread.NamedThreadFactory; +import com.google.common.base.Function; import freenet.keys.FreenetURI; import com.google.common.base.Optional; @@ -330,6 +331,11 @@ public class Core extends AbstractService implements SoneProvider { } @Override + public Function> getSone() { + return database.getSone(); + } + + @Override public Optional getSone(String id) { synchronized (sones) { return Optional.fromNullable(sones.get(id)); diff --git a/src/main/java/net/pterodactylus/sone/database/SoneProvider.java b/src/main/java/net/pterodactylus/sone/database/SoneProvider.java index 993804f..b944ab8 100644 --- a/src/main/java/net/pterodactylus/sone/database/SoneProvider.java +++ b/src/main/java/net/pterodactylus/sone/database/SoneProvider.java @@ -21,6 +21,7 @@ import java.util.Collection; import net.pterodactylus.sone.data.Sone; +import com.google.common.base.Function; import com.google.common.base.Optional; /** @@ -30,6 +31,8 @@ import com.google.common.base.Optional; */ public interface SoneProvider { + Function> getSone(); + /** * Returns the Sone with the given ID, or {@link Optional#absent()} if it * does not exist. 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 e311a5e..02ca290 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -173,6 +173,16 @@ public class MemoryDatabase extends AbstractService implements Database { } @Override + public Function> getSone() { + return new Function>() { + @Override + public Optional apply(String soneId) { + return (soneId == null) ? Optional.absent() : getSone(soneId); + } + }; + } + + @Override public Optional getSone(String soneId) { lock.readLock().lock(); try { -- 2.7.4