X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FAlbum.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FAlbum.java;h=bf8f3ec41a1eed136880f16707181f4affbfc054;hp=576c73a9a8b9ebd34b9ceb218eb349d12b1669aa;hb=5c5bee980f9cab5792e34d1c9840f73b8b191830;hpb=faf66247a34f64946990a985d2ea3003465969cb diff --git a/src/main/java/net/pterodactylus/sone/data/Album.java b/src/main/java/net/pterodactylus/sone/data/Album.java index 576c73a..bf8f3ec 100644 --- a/src/main/java/net/pterodactylus/sone/data/Album.java +++ b/src/main/java/net/pterodactylus/sone/data/Album.java @@ -17,78 +17,13 @@ package net.pterodactylus.sone.data; -import static java.util.Arrays.asList; -import static java.util.Collections.emptyList; - -import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import javax.annotation.Nonnull; - -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.collect.FluentIterable; -import com.google.common.collect.ImmutableList; /** * Container for images that can also contain nested {@link Album}s. */ public interface Album extends Identified, Fingerprintable { - /** Function that flattens the given album and all albums beneath it. */ - Function> FLATTENER = new Function>() { - - @Override - @Nonnull - public List apply(Album album) { - if (album == null) { - return emptyList(); - } - List albums = new ArrayList<>(); - albums.add(album); - for (Album subAlbum : album.getAlbums()) { - albums.addAll(FluentIterable.from(ImmutableList.of(subAlbum)).transformAndConcat(FLATTENER).toList()); - } - return albums; - } - }; - - /** Function that transforms an album into the images it contains. */ - Function> IMAGES = new Function>() { - - @Override - @Nonnull - public List apply(Album album) { - return (album != null) ? album.getImages() : Collections.emptyList(); - } - }; - - /** - * Filter that removes all albums that do not have any images in any album - * below it. - */ - Predicate NOT_EMPTY = new Predicate() { - - @Override - public boolean apply(Album album) { - /* so, we flatten all albums below the given one and check whether at least one album… */ - return FluentIterable.from(asList(album)).transformAndConcat(FLATTENER).anyMatch(new Predicate() { - - @Override - public boolean apply(Album album) { - /* …contains any inserted images. */ - return !album.getImages().isEmpty() && FluentIterable.from(album.getImages()).allMatch(new Predicate() { - - @Override - public boolean apply(Image input) { - return input.isInserted(); - } - }); - } - }); - } - }; - /** * Returns the ID of this album. *