X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FAlbumAccessor.java;h=e19a89aa8dc70b925871a27d1d102cb9c681e52c;hp=96891e5a52a23447022b3e328b38dc045344e352;hb=419098bcd6215125408b29e60bd888e60979d37b;hpb=6e9a43ccd93ae125720547c0fe421dc81a54ba90 diff --git a/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java b/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java index 96891e5..e19a89a 100644 --- a/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java @@ -1,5 +1,5 @@ /* - * Sone - AlbumAccessor.java - Copyright © 2011–2013 David Roden + * Sone - AlbumAccessor.java - Copyright © 2011–2015 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,9 +18,7 @@ package net.pterodactylus.sone.template; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import net.pterodactylus.sone.data.Album; import net.pterodactylus.util.template.Accessor; @@ -43,36 +41,66 @@ 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>(); + List backlinks = new ArrayList(); Album currentAlbum = album; - while (currentAlbum != null) { - backlinks.add(0, createLink("imageBrowser.html?album=" + currentAlbum.getId(), currentAlbum.getTitle())); + while (!currentAlbum.isRoot()) { + backlinks.add(0, new Link("imageBrowser.html?album=" + currentAlbum.getId(), currentAlbum.getTitle())); currentAlbum = currentAlbum.getParent(); } - backlinks.add(0, createLink("imageBrowser.html?sone=" + album.getSone().getId(), SoneAccessor.getNiceName(album.getSone()))); + backlinks.add(0, new Link("imageBrowser.html?sone=" + album.getSone().getId(), SoneAccessor.getNiceName(album.getSone()))); return backlinks; } return super.get(templateContext, object, member); } - // - // PRIVATE METHODS - // - /** - * Creates a map containing mappings for “target” and “link.” + * Container for links. * - * @param target - * The target to link to - * @param name - * The name of the link - * @return The created map containing the mappings + * @author David ‘Bombe’ Roden */ - private static Map createLink(String target, String name) { - Map link = new HashMap(); - link.put("target", target); - link.put("name", name); - return link; + private static class Link { + + /** The target of the link. */ + private final String target; + + /** The name of the link. */ + private final String name; + + /** + * Creates a new link. + * + * @param target + * The target of the link + * @param name + * The name of the link + */ + private Link(String target, String name) { + this.target = target; + this.name = name; + } + + // + // ACCESSORS + // + + /** + * Returns the target of the link. + * + * @return The target of the link + */ + public String getTarget() { + return target; + } + + /** + * Returns the name of the link. + * + * @return The name of the link + */ + public String getName() { + return name; + } + } }