Add method to get all images of an album to ImageProvider.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 14 Oct 2013 04:26:20 +0000 (06:26 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:25 +0000 (22:25 +0100)
src/main/java/net/pterodactylus/sone/database/ImageProvider.java
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java

index c9ad9e1..dcfdc92 100644 (file)
@@ -17,6 +17,9 @@
 
 package net.pterodactylus.sone.database;
 
+import java.util.List;
+
+import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Image;
 
 import com.google.common.base.Optional;
@@ -30,4 +33,6 @@ public interface ImageProvider {
 
        Optional<Image> getImage(String imageId);
 
+       List<Image> getImages(Album parent);
+
 }
index 0c38c2c..538d97f 100644 (file)
@@ -532,6 +532,16 @@ public class MemoryDatabase extends AbstractService implements Database {
                }
        }
 
+       @Override
+       public List<Image> getImages(Album parent) {
+               lock.readLock().lock();
+               try {
+                       return from(albumImages.get(parent.getId())).transformAndConcat(getImage()).toList();
+               } finally {
+                       lock.readLock().unlock();
+               }
+       }
+
        //
        // IMAGESTORE METHODS
        //
@@ -867,4 +877,13 @@ public class MemoryDatabase extends AbstractService implements Database {
                };
        }
 
+       private Function<String, Iterable<Image>> getImage() {
+               return new Function<String, Iterable<Image>>() {
+                       @Override
+                       public Iterable<Image> apply(String input) {
+                               return (input == null) ? Collections.<Image>emptyList() : getImage(input).asSet();
+                       }
+               };
+       }
+
 }