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

index 8fcfe10..8e6f1b0 100644 (file)
@@ -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<String, Optional<Sone>> getSone() {
+               return database.getSone();
+       }
+
+       @Override
        public Optional<Sone> getSone(String id) {
                synchronized (sones) {
                        return Optional.fromNullable(sones.get(id));
index 993804f..b944ab8 100644 (file)
@@ -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<String, Optional<Sone>> getSone();
+
        /**
         * Returns the Sone with the given ID, or {@link Optional#absent()} if it
         * does not exist.
index e311a5e..02ca290 100644 (file)
@@ -173,6 +173,16 @@ public class MemoryDatabase extends AbstractService implements Database {
        }
 
        @Override
+       public Function<String, Optional<Sone>> getSone() {
+               return new Function<String, Optional<Sone>>() {
+                       @Override
+                       public Optional<Sone> apply(String soneId) {
+                               return (soneId == null) ? Optional.<Sone>absent() : getSone(soneId);
+                       }
+               };
+       }
+
+       @Override
        public Optional<Sone> getSone(String soneId) {
                lock.readLock().lock();
                try {