From: David ‘Bombe’ Roden Date: Mon, 4 Nov 2013 05:26:47 +0000 (+0100) Subject: Add method to expose a Sone loader. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=0b8194c25d3dc9a68601b95e13adc4a5d92628c1;hp=18a698e6a649539b6a4870d5928f91bcb9d37f35;p=Sone.git Add method to expose a Sone loader. --- 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 {