From: David ‘Bombe’ Roden Date: Mon, 14 Oct 2013 04:26:20 +0000 (+0200) Subject: Add method to get all images of an album to ImageProvider. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=d37132932d423abaca088fdf3496b9b0f38e3ae3;p=Sone.git Add method to get all images of an album to ImageProvider. --- diff --git a/src/main/java/net/pterodactylus/sone/database/ImageProvider.java b/src/main/java/net/pterodactylus/sone/database/ImageProvider.java index c9ad9e1..dcfdc92 100644 --- a/src/main/java/net/pterodactylus/sone/database/ImageProvider.java +++ b/src/main/java/net/pterodactylus/sone/database/ImageProvider.java @@ -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 getImage(String imageId); + List getImages(Album parent); + } 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 0c38c2c..538d97f 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -532,6 +532,16 @@ public class MemoryDatabase extends AbstractService implements Database { } } + @Override + public List 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> getImage() { + return new Function>() { + @Override + public Iterable apply(String input) { + return (input == null) ? Collections.emptyList() : getImage(input).asSet(); + } + }; + } + }