X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FSone.java;h=be3a660cf1323394b1450911ca27ca63319edb44;hb=e2e8fe4fd31ebfc73fa9ea2bd77aba71ee2939c7;hp=b8db269712c4ee3eac5bf165097b5a304c9cc45f;hpb=0df5e91852f737d760c5a9f54c5667309fbadcc2;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index b8db269..be3a660 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -645,6 +645,41 @@ public class Sone implements Fingerprintable, Comparable { } /** + * 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 getAllAlbums() { + List flatAlbums = new ArrayList(); + flatAlbums.addAll(albums); + int lastAlbumIndex = 0; + while (lastAlbumIndex < flatAlbums.size()) { + int previousAlbumCount = flatAlbums.size(); + for (Album album : new ArrayList(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 getAllImages() { + List allImages = new ArrayList(); + for (Album album : getAllAlbums()) { + allImages.addAll(album.getImages()); + } + return allImages; + } + + /** * Adds an album to this Sone. * * @param album @@ -681,6 +716,46 @@ public class Sone implements Fingerprintable, Comparable { } /** + * Moves the given album up in this album’s albums. If the album is already + * the first album, nothing happens. + * + * @param album + * The album to move up + * @return The album that the given album swapped the place with, or + * null if the album did not change its place + */ + public Album moveAlbumUp(Album album) { + Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.getSone(), this).isNull("Album Parent", album.getParent()).check(); + int oldIndex = albums.indexOf(album); + if (oldIndex <= 0) { + return null; + } + albums.remove(oldIndex); + albums.add(oldIndex - 1, album); + return albums.get(oldIndex); + } + + /** + * Moves the given album down in this album’s albums. If the album is + * already the last album, nothing happens. + * + * @param album + * The album to move down + * @return The album that the given album swapped the place with, or + * null if the album did not change its place + */ + public Album moveAlbumDown(Album album) { + Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.getSone(), this).isNull("Album Parent", album.getParent()).check(); + int oldIndex = albums.indexOf(album); + if ((oldIndex < 0) || (oldIndex >= (albums.size() - 1))) { + return null; + } + albums.remove(oldIndex); + albums.add(oldIndex + 1, album); + return albums.get(oldIndex); + } + + /** * Returns Sone-specific options. * * @return The options of this Sone @@ -707,7 +782,6 @@ public class Sone implements Fingerprintable, Comparable { } fingerprint.append(")"); - @SuppressWarnings("hiding") List replies = new ArrayList(getReplies()); Collections.sort(replies, Reply.TIME_COMPARATOR); fingerprint.append("Replies("); @@ -716,7 +790,6 @@ public class Sone implements Fingerprintable, Comparable { } fingerprint.append(')'); - @SuppressWarnings("hiding") List likedPostIds = new ArrayList(getLikedPostIds()); Collections.sort(likedPostIds); fingerprint.append("LikedPosts("); @@ -725,7 +798,6 @@ public class Sone implements Fingerprintable, Comparable { } fingerprint.append(')'); - @SuppressWarnings("hiding") List likedReplyIds = new ArrayList(getLikedReplyIds()); Collections.sort(likedReplyIds); fingerprint.append("LikedReplies("); @@ -744,33 +816,6 @@ public class Sone implements Fingerprintable, Comparable { } // - // 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 flattenAlbums(Collection albums) { - List flatAlbums = new ArrayList(); - flatAlbums.addAll(albums); - int lastAlbumIndex = 0; - while (lastAlbumIndex < flatAlbums.size()) { - int previousAlbumCount = flatAlbums.size(); - for (Album album : new ArrayList(flatAlbums.subList(lastAlbumIndex, flatAlbums.size()))) { - flatAlbums.addAll(album.getAlbums()); - } - lastAlbumIndex = previousAlbumCount; - } - return flatAlbums; - } - - // // INTERFACE Comparable //