Add method to expose a Sone loader to the Sone provider.
[Sone.git] / src / main / java / net / pterodactylus / sone / database / memory / MemoryDatabase.java
index eb0d20a..4ee375e 100644 (file)
@@ -56,6 +56,7 @@ import net.pterodactylus.sone.database.SoneProvider;
 import net.pterodactylus.util.config.Configuration;
 import net.pterodactylus.util.config.ConfigurationException;
 
+import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.base.Predicate;
 import com.google.common.collect.HashMultimap;
@@ -239,6 +240,16 @@ public class MemoryDatabase extends AbstractService implements Database {
        }
 
        @Override
+       public Function<String, Optional<Sone>> soneLoader() {
+               return new Function<String, Optional<Sone>>() {
+                       @Override
+                       public Optional<Sone> apply(String soneId) {
+                               return getSone(soneId);
+                       }
+               };
+       }
+
+       @Override
        public Optional<Sone> getSone(String soneId) {
                lock.readLock().lock();
                try {
@@ -676,22 +687,6 @@ public class MemoryDatabase extends AbstractService implements Database {
                }
        }
 
-       /**
-        * Returns all replies by the given Sone.
-        *
-        * @param id
-        *              The ID of the Sone
-        * @return The post replies of the Sone, sorted by time (newest first)
-        */
-       private Collection<PostReply> getRepliesFrom(String id) {
-               lock.readLock().lock();
-               try {
-                       return unmodifiableCollection(sonePostReplies.get(id));
-               } finally {
-                       lock.readLock().unlock();
-               }
-       }
-
        /** Loads the known post replies. */
        private void loadKnownPostReplies() {
                Set<String> knownPostReplies = configurationLoader.loadKnownPostReplies();