From 7c3ff19e96a5dcd31c2530f8d69ff1e5ccb33ca3 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:23:30 +0200 Subject: [PATCH] Add method to get child albums of an album to AlbumProvider. --- .../pterodactylus/sone/database/AlbumProvider.java | 4 ++++ .../sone/database/memory/MemoryDatabase.java | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/database/AlbumProvider.java b/src/main/java/net/pterodactylus/sone/database/AlbumProvider.java index b83b179..c035623 100644 --- a/src/main/java/net/pterodactylus/sone/database/AlbumProvider.java +++ b/src/main/java/net/pterodactylus/sone/database/AlbumProvider.java @@ -17,6 +17,8 @@ package net.pterodactylus.sone.database; +import java.util.List; + import net.pterodactylus.sone.data.Album; import com.google.common.base.Optional; @@ -38,4 +40,6 @@ public interface AlbumProvider { */ Optional getAlbum(String albumId); + List getAlbums(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 4437baf..451be3a 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -21,6 +21,7 @@ import static com.google.common.base.Optional.fromNullable; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Predicates.not; import static com.google.common.collect.FluentIterable.from; +import static java.util.Collections.emptyList; import static net.pterodactylus.sone.data.Sone.LOCAL_SONE_FILTER; import java.util.ArrayList; @@ -52,6 +53,7 @@ import net.pterodactylus.sone.database.SoneBuilder; 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.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; @@ -480,6 +482,16 @@ public class MemoryDatabase extends AbstractService implements Database { } } + @Override + public List getAlbums(Album parent) { + lock.readLock().lock(); + try { + return from(albumChildren.get(parent.getId())).transformAndConcat(getAlbum()).toList(); + } finally { + lock.readLock().unlock(); + } + } + // // ALBUMSTORE METHODS // @@ -846,4 +858,13 @@ public class MemoryDatabase extends AbstractService implements Database { } } + private Function> getAlbum() { + return new Function>() { + @Override + public Iterable apply(String input) { + return (input == null) ? Collections.emptyList() : getAlbum(input).asSet(); + } + }; + } + } -- 2.7.4