Include album fingerprints in Sone fingerprint.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Sone.java
index aa4a155..3aa604e 100644 (file)
@@ -696,16 +696,43 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
                }
                fingerprint.append(')');
 
-//             fingerprint.append("Albums(");
-//             for (Album album : albums) {
-//                     fingerprint.append(album.getFingerprint());
-//             }
-//             fingerprint.append(')');
+               fingerprint.append("Albums(");
+               for (Album album : albums) {
+                       fingerprint.append(album.getFingerprint());
+               }
+               fingerprint.append(')');
 
                return fingerprint.toString();
        }
 
        //
+       // 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>
        //