From bb0081d5e34a59ccfb275c166e5935a2acb65a2c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 18 Oct 2010 21:07:59 +0200 Subject: [PATCH] Sort known Sones by nice name and last update time. --- .../net/pterodactylus/sone/web/KnownSonesPage.java | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java b/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java index 0127172..ea6f786 100644 --- a/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java +++ b/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java @@ -17,6 +17,13 @@ package net.pterodactylus.sone.web; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.template.SoneAccessor; import net.pterodactylus.util.template.Template; /** @@ -48,7 +55,20 @@ public class KnownSonesPage extends SoneTemplatePage { @Override protected void processTemplate(Request request, Template template) throws RedirectException { super.processTemplate(request, template); - template.set("knownSones", webInterface.core().getKnownSones()); + List knownSones = new ArrayList(webInterface.core().getKnownSones()); + Collections.sort(knownSones, new Comparator() { + + @Override + public int compare(Sone leftSone, Sone rightSone) { + int diff = SoneAccessor.getNiceName(leftSone).compareTo(SoneAccessor.getNiceName(rightSone)); + if (diff != 0) { + return diff; + } + return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, rightSone.getTime() - leftSone.getTime())); + } + + }); + template.set("knownSones", knownSones); } } -- 2.7.4