From 0382e0afaa2bf1c193f4092a6468c99ff942df0c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 16 Feb 2013 02:27:01 +0100 Subject: [PATCH] Add function to flatten an album and all albums beneath it. --- src/main/java/net/pterodactylus/sone/data/Album.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/data/Album.java b/src/main/java/net/pterodactylus/sone/data/Album.java index 7103871..5375d98 100644 --- a/src/main/java/net/pterodactylus/sone/data/Album.java +++ b/src/main/java/net/pterodactylus/sone/data/Album.java @@ -32,6 +32,8 @@ import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.base.Predicates; import com.google.common.collect.Collections2; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableList; import com.google.common.hash.Hasher; import com.google.common.hash.Hashing; @@ -51,6 +53,20 @@ public class Album implements Fingerprintable { } }; + /** Function that flattens the given album and all albums beneath it. */ + public static final Function> FLATTENER = new Function>() { + + @Override + public List apply(Album album) { + List albums = new ArrayList(); + albums.add(album); + for (Album subAlbum : album.getAlbums()) { + albums.addAll(FluentIterable.from(ImmutableList.of(subAlbum)).transformAndConcat(FLATTENER).toList()); + } + return albums; + } + }; + /** The ID of this album. */ private final String id; -- 2.7.4