Add method that returns all images of a Sone.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Sone.java
index e124387..be3a660 100644 (file)
@@ -645,6 +645,41 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
        }
 
        /**
+        * Returns a flattened list of all albums of this Sone. The resulting list
+        * contains parent albums before child albums so that the resulting list can
+        * be parsed in a single pass.
+        *
+        * @return The flattened albums
+        */
+       public List<Album> getAllAlbums() {
+               List<Album> flatAlbums = new ArrayList<Album>();
+               flatAlbums.addAll(albums);
+               int lastAlbumIndex = 0;
+               while (lastAlbumIndex < flatAlbums.size()) {
+                       int previousAlbumCount = flatAlbums.size();
+                       for (Album album : new ArrayList<Album>(flatAlbums.subList(lastAlbumIndex, flatAlbums.size()))) {
+                               flatAlbums.addAll(album.getAlbums());
+                       }
+                       lastAlbumIndex = previousAlbumCount;
+               }
+               return flatAlbums;
+       }
+
+       /**
+        * Returns all images of a Sone. Images of a album are inserted into this
+        * list before images of all child albums.
+        *
+        * @return The list of all images
+        */
+       public List<Image> getAllImages() {
+               List<Image> allImages = new ArrayList<Image>();
+               for (Album album : getAllAlbums()) {
+                       allImages.addAll(album.getImages());
+               }
+               return allImages;
+       }
+
+       /**
         * Adds an album to this Sone.
         *
         * @param album
@@ -781,33 +816,6 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
        }
 
        //
-       // STATIC METHODS
-       //
-
-       /**
-        * Flattens the given top-level albums so that the resulting list contains
-        * parent albums before child albums and the resulting list can be parsed in
-        * a single pass.
-        *
-        * @param albums
-        *            The albums to flatten
-        * @return The flattened albums
-        */
-       public static List<Album> flattenAlbums(Collection<? extends Album> albums) {
-               List<Album> flatAlbums = new ArrayList<Album>();
-               flatAlbums.addAll(albums);
-               int lastAlbumIndex = 0;
-               while (lastAlbumIndex < flatAlbums.size()) {
-                       int previousAlbumCount = flatAlbums.size();
-                       for (Album album : new ArrayList<Album>(flatAlbums.subList(lastAlbumIndex, flatAlbums.size()))) {
-                               flatAlbums.addAll(album.getAlbums());
-                       }
-                       lastAlbumIndex = previousAlbumCount;
-               }
-               return flatAlbums;
-       }
-
-       //
        // INTERFACE Comparable<Sone>
        //