Add filter for empty albums.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 5 Jul 2013 18:57:59 +0000 (20:57 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 5 Jul 2013 18:57:59 +0000 (20:57 +0200)
src/main/java/net/pterodactylus/sone/data/Album.java

index 5375d98..cb7b4f3 100644 (file)
@@ -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<Album> NOT_EMPTY = new Predicate<Album>() {
+
+               @Override
+               public boolean apply(Album album) {
+                       return FluentIterable.from(asList(album)).transformAndConcat(FLATTENER).anyMatch(new Predicate<Album>() {
+
+                               @Override
+                               public boolean apply(Album album) {
+                                       return !album.getImages().isEmpty();
+                               }
+                       });
+               }
+       };
+
        /** The ID of this album. */
        private final String id;