-public class Album implements Fingerprintable {
-
- /** The ID of this album. */
- private final String id;
-
- /** The Sone this album belongs to. */
- private Sone sone;
-
- /** Nested albums. */
- private final List<Album> albums = new ArrayList<Album>();
-
- /** The images in this album. */
- private final List<Image> images = new ArrayList<Image>();
-
- /** The parent album. */
- private Album parent;
-
- /** The name of this album. */
- private String name;
-
- /** The description of this album. */
- private String description;
-
- /** The index of the album picture. */
- private int albumImage = -1;
-
- /**
- * Creates a new album with a random ID.
- */
- public Album() {
- this(UUID.randomUUID().toString());
- }
+public interface Album extends Identified, Fingerprintable {
+
+ /** Function that flattens the given album and all albums beneath it. */
+ Function<Album, List<Album>> FLATTENER = new Function<Album, List<Album>>() {
+
+ @Override
+ @Nonnull
+ public List<Album> apply(Album album) {
+ if (album == null) {
+ return emptyList();
+ }
+ List<Album> albums = new ArrayList<>();
+ albums.add(album);
+ for (Album subAlbum : album.getAlbums()) {
+ albums.addAll(FluentIterable.from(ImmutableList.of(subAlbum)).transformAndConcat(FLATTENER).toList());
+ }
+ return albums;
+ }
+ };