From: David ‘Bombe’ Roden Date: Wed, 20 Oct 2010 14:25:57 +0000 (+0200) Subject: Sort local Sones for login page. X-Git-Tag: 0.1-RC1~148 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=52fa2e71988322c2dd32074355628fb8541bb0d6;p=Sone.git Sort local Sones for login page. --- diff --git a/src/main/java/net/pterodactylus/sone/web/LoginPage.java b/src/main/java/net/pterodactylus/sone/web/LoginPage.java index 39c3cdc..1dd0659 100644 --- a/src/main/java/net/pterodactylus/sone/web/LoginPage.java +++ b/src/main/java/net/pterodactylus/sone/web/LoginPage.java @@ -17,9 +17,13 @@ package net.pterodactylus.sone.web; -import java.util.Set; +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.sone.web.page.Page.Request.Method; import net.pterodactylus.util.template.Template; import freenet.clients.http.ToadletContext; @@ -53,7 +57,19 @@ public class LoginPage extends SoneTemplatePage { @Override protected void processTemplate(Request request, Template template) throws RedirectException { super.processTemplate(request, template); - Set localSones = webInterface.core().getSones(); + List localSones = new ArrayList(webInterface.core().getSones()); + Collections.sort(localSones, 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("sones", localSones); if (request.getMethod() == Method.POST) { String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone-id", 100);