From fd560d013c7de7b8c70b65156a41d4a6bc9aeb06 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 24 Jan 2013 06:06:54 +0100 Subject: [PATCH] Use different way to get replies for a post. --- .../java/net/pterodactylus/sone/core/Core.java | 27 +++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 93a5f00..4356120 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -86,9 +86,12 @@ import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.service.AbstractService; import net.pterodactylus.util.thread.NamedThreadFactory; +import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.Collections2; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.Ordering; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; import com.google.inject.Inject; @@ -587,18 +590,20 @@ public class Core extends AbstractService implements SoneProvider, PostProvider * The post to get all replies for * @return All replies for the given post */ - public List getReplies(Post post) { - Set sones = getSones(); - List replies = new ArrayList(); - for (Sone sone : sones) { - for (PostReply reply : sone.getReplies()) { - if (reply.getPost().equals(post)) { - replies.add(reply); - } + public List getReplies(final Post post) { + return Ordering.from(Reply.TIME_COMPARATOR).sortedCopy(FluentIterable.from(getSones()).transformAndConcat(new Function>() { + + @Override + public Iterable apply(Sone sone) { + return sone.getReplies(); } - } - Collections.sort(replies, Reply.TIME_COMPARATOR); - return replies; + }).filter(new Predicate() { + + @Override + public boolean apply(PostReply reply) { + return post.equals(reply.getPost()); + } + })); } /** -- 2.7.4