From 40e4cfe73a346f7dc9d46aedbeccd6a38798f175 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 9 Nov 2013 16:15:49 +0100 Subject: [PATCH] Extract some functionality into their own methods. --- .../pterodactylus/sone/template/AlbumAccessor.java | 31 ++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java b/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java index 740da47..0ab114b 100644 --- a/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java @@ -17,10 +17,13 @@ package net.pterodactylus.sone.template; +import static net.pterodactylus.sone.template.SoneAccessor.getNiceName; + import java.util.ArrayList; import java.util.List; import net.pterodactylus.sone.data.Album; +import net.pterodactylus.sone.data.Sone; import net.pterodactylus.util.template.Accessor; import net.pterodactylus.util.template.ReflectionAccessor; import net.pterodactylus.util.template.TemplateContext; @@ -38,20 +41,32 @@ public class AlbumAccessor extends ReflectionAccessor { public Object get(TemplateContext templateContext, Object object, String member) { Album album = (Album) object; if ("backlinks".equals(member)) { - List backlinks = new ArrayList(); - Album currentAlbum = album; - while (!currentAlbum.isRoot()) { - backlinks.add(0, new Link("imageBrowser.html?album=" + currentAlbum.getId(), currentAlbum.getTitle())); - currentAlbum = currentAlbum.getParent(); - } - backlinks.add(0, new Link("imageBrowser.html?sone=" + album.getSone().getId(), SoneAccessor.getNiceName(album.getSone()))); - return backlinks; + return generateBacklinks(album); } else if ("albumImage".equals(member)) { return album.getAlbumImage().orNull(); } return super.get(templateContext, object, member); } + private Object generateBacklinks(Album album) { + List backlinks = new ArrayList(); + Album currentAlbum = album; + while (!currentAlbum.isRoot()) { + backlinks.add(0, generateLinkToAlbum(currentAlbum)); + currentAlbum = currentAlbum.getParent(); + } + backlinks.add(0, generateLinkToSone(album.getSone())); + return backlinks; + } + + private Link generateLinkToSone(Sone sone) { + return new Link("imageBrowser.html?sone=" + sone.getId(), getNiceName(sone)); + } + + private Link generateLinkToAlbum(Album currentAlbum) { + return new Link("imageBrowser.html?album=" + currentAlbum.getId(), currentAlbum.getTitle()); + } + /** * Container for links. * -- 2.7.4