From 6ec2e6efa1206bad95571398f4dcc4675af98720 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 14 Oct 2010 15:41:47 +0200 Subject: [PATCH] Always return the replies sorted by time, oldest first. --- src/main/java/net/pterodactylus/sone/data/Post.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/data/Post.java b/src/main/java/net/pterodactylus/sone/data/Post.java index 15992a3..33871c6 100644 --- a/src/main/java/net/pterodactylus/sone/data/Post.java +++ b/src/main/java/net/pterodactylus/sone/data/Post.java @@ -17,8 +17,11 @@ package net.pterodactylus.sone.data; +import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.UUID; @@ -135,8 +138,17 @@ public class Post { * * @return All replies to this post */ - public Set getReplies() { - return Collections.unmodifiableSet(replies); + public List getReplies() { + List sortedReplies = new ArrayList(replies); + Collections.sort(sortedReplies, new Comparator() { + + @Override + public int compare(Reply leftReply, Reply rightReply) { + return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, leftReply.getTime() - rightReply.getTime())); + } + + }); + return sortedReplies; } /** -- 2.7.4