+ /** Function that flattens the given album and all albums beneath it. */
+ public static final Function<Album, List<Album>> FLATTENER = new Function<Album, List<Album>>() {
+
+ @Override
+ public List<Album> apply(Album album) {
+ List<Album> albums = new ArrayList<Album>();
+ albums.add(album);
+ for (Album subAlbum : album.getAlbums()) {
+ albums.addAll(FluentIterable.from(ImmutableList.of(subAlbum)).transformAndConcat(FLATTENER).toList());
+ }
+ return albums;
+ }
+ };
+
+ /**
+ * 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();
+ }
+ });
+ }
+ };
+