From d37132932d423abaca088fdf3496b9b0f38e3ae3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 14 Oct 2013 06:26:20 +0200 Subject: [PATCH] Add method to get all images of an album to ImageProvider. --- .../pterodactylus/sone/database/ImageProvider.java | 5 +++++ .../sone/database/memory/MemoryDatabase.java | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) 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(); + } + }; + } + } -- 2.7.4