From b2d80d0a83f7cd3880e18349bea3ea102389c316 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 5 Jul 2013 20:57:59 +0200 Subject: [PATCH] Add filter for empty albums. --- src/main/java/net/pterodactylus/sone/data/Album.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/data/Album.java b/src/main/java/net/pterodactylus/sone/data/Album.java index 5375d98..cb7b4f3 100644 --- a/src/main/java/net/pterodactylus/sone/data/Album.java +++ b/src/main/java/net/pterodactylus/sone/data/Album.java @@ -20,6 +20,7 @@ package net.pterodactylus.sone.data; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import static java.util.Arrays.asList; import java.util.ArrayList; import java.util.Comparator; @@ -30,6 +31,7 @@ import java.util.UUID; import com.google.common.base.Function; import com.google.common.base.Optional; +import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.Collections2; import com.google.common.collect.FluentIterable; @@ -67,6 +69,24 @@ public class Album implements Fingerprintable { } }; + /** + * Filter that removes all albums that do not have any images in any album + * below it. + */ + public static final Predicate NOT_EMPTY = new Predicate() { + + @Override + public boolean apply(Album album) { + return FluentIterable.from(asList(album)).transformAndConcat(FLATTENER).anyMatch(new Predicate() { + + @Override + public boolean apply(Album album) { + return !album.getImages().isEmpty(); + } + }); + } + }; + /** The ID of this album. */ private final String id; -- 2.7.4