From: David ‘Bombe’ Roden Date: Sat, 9 Nov 2013 15:15:49 +0000 (+0100) Subject: Extract some functionality into their own methods. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=40e4cfe73a346f7dc9d46aedbeccd6a38798f175;p=Sone.git Extract some functionality into their own methods. --- 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. *