From 800a866c8d935a386b4fb7182f4647950bb86791 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 11 Jul 2013 22:47:00 +0200 Subject: [PATCH] Use a custom container class instead of messing around with maps. --- .../pterodactylus/sone/template/AlbumAccessor.java | 68 +++++++++++++++------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java b/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java index fcd7a70..13b4d65 100644 --- a/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java @@ -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.equals(album.getSone().getRootAlbum())) { - backlinks.add(0, createLink("imageBrowser.html?album=" + currentAlbum.getId(), currentAlbum.getTitle())); + 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; + } + } } -- 2.7.4