From de928fae67034e4694d7d8e8ea73573d400491f4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 16 Feb 2013 02:33:11 +0100 Subject: [PATCH] Remove getAllAlbums() method, use album flattener. --- .../java/net/pterodactylus/sone/core/Core.java | 3 ++- .../net/pterodactylus/sone/core/SoneInserter.java | 4 +++- .../java/net/pterodactylus/sone/data/Sone.java | 24 ++-------------------- .../pterodactylus/sone/web/ImageBrowserPage.java | 3 ++- 4 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 2d24690..d66e032 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -94,6 +94,7 @@ import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.Collections2; +import com.google.common.collect.FluentIterable; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; import com.google.inject.Inject; @@ -1867,7 +1868,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, configuration.getStringValue(sonePrefix + "/Friends/" + friendCounter + "/ID").setValue(null); /* save albums. first, collect in a flat structure, top-level first. */ - List albums = sone.getAllAlbums(); + List albums = FluentIterable.from(sone.getAlbums()).transformAndConcat(Album.FLATTENER).toList(); int albumCounter = 0; for (Album album : albums) { diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java index 48241aa..8efcc73 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -29,6 +29,7 @@ import java.util.logging.Logger; import net.pterodactylus.sone.core.event.SoneInsertAbortedEvent; import net.pterodactylus.sone.core.event.SoneInsertedEvent; import net.pterodactylus.sone.core.event.SoneInsertingEvent; +import net.pterodactylus.sone.data.Album; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; @@ -47,6 +48,7 @@ import net.pterodactylus.util.template.TemplateException; import net.pterodactylus.util.template.TemplateParser; import net.pterodactylus.util.template.XmlFilter; +import com.google.common.collect.FluentIterable; import com.google.common.collect.Ordering; import com.google.common.eventbus.EventBus; @@ -289,7 +291,7 @@ public class SoneInserter extends AbstractService { soneProperties.put("replies", Ordering.from(Reply.TIME_COMPARATOR).reverse().sortedCopy(sone.getReplies())); soneProperties.put("likedPostIds", new HashSet(sone.getLikedPostIds())); soneProperties.put("likedReplyIds", new HashSet(sone.getLikedReplyIds())); - soneProperties.put("albums", sone.getAllAlbums()); + soneProperties.put("albums", FluentIterable.from(sone.getAlbums()).transformAndConcat(Album.FLATTENER).toList()); } // diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index a3e872b..8b08b17 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -38,6 +38,7 @@ import net.pterodactylus.sone.template.SoneAccessor; import net.pterodactylus.util.logging.Logging; import com.google.common.base.Predicate; +import com.google.common.collect.FluentIterable; import com.google.common.hash.Hasher; import com.google.common.hash.Hashing; @@ -770,27 +771,6 @@ 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. * @@ -798,7 +778,7 @@ public class Sone implements Fingerprintable, Comparable { */ public List getAllImages() { List allImages = new ArrayList(); - for (Album album : getAllAlbums()) { + for (Album album : FluentIterable.from(getAlbums()).transformAndConcat(Album.FLATTENER).toList()) { allImages.addAll(album.getImages()); } return allImages; diff --git a/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java b/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java index 53c22f2..37268ec 100644 --- a/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java @@ -23,6 +23,7 @@ import java.util.Collections; import java.util.List; import com.google.common.base.Optional; +import com.google.common.collect.FluentIterable; import net.pterodactylus.sone.data.Album; import net.pterodactylus.sone.data.Image; @@ -89,7 +90,7 @@ public class ImageBrowserPage extends SoneTemplatePage { templateContext.set("galleryRequested", true); List albums = new ArrayList(); for (Sone sone : webInterface.getCore().getSones()) { - albums.addAll(sone.getAllAlbums()); + albums.addAll(FluentIterable.from(sone.getAlbums()).transformAndConcat(Album.FLATTENER).toList()); } Collections.sort(albums, Album.TITLE_COMPARATOR); Pagination albumPagination = new Pagination(albums, 12).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0)); -- 2.7.4