X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=inline;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FReplyGroupFilter.java;h=c093e6fe01969fc665954909d38e9997470433f7;hb=607feeb5ec4a5c6d75562456bdf0a10f8ad12ea8;hp=bcf73d8ab97371b881479b36bf533e0b2481cb18;hpb=6e9a43ccd93ae125720547c0fe421dc81a54ba90;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/template/ReplyGroupFilter.java b/src/main/java/net/pterodactylus/sone/template/ReplyGroupFilter.java
index bcf73d8..c093e6f 100644
--- a/src/main/java/net/pterodactylus/sone/template/ReplyGroupFilter.java
+++ b/src/main/java/net/pterodactylus/sone/template/ReplyGroupFilter.java
@@ -1,5 +1,5 @@
/*
- * Sone - ReplyGroupFilter.java - Copyright © 2010â2013 David Roden
+ * Sone - ReplyGroupFilter.java - Copyright © 2010â2019 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import net.pterodactylus.sone.data.Post;
@@ -29,14 +30,10 @@ import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.util.template.Filter;
import net.pterodactylus.util.template.TemplateContext;
-import com.google.common.base.Optional;
-
/**
* {@link Filter} implementation that groups replies by the post the are in
* reply to, returning a map with the post as key and the list of replies as
* values.
- *
- * @author David âBombeâ Roden
*/
public class ReplyGroupFilter implements Filter {
@@ -47,36 +44,33 @@ public class ReplyGroupFilter implements Filter {
public Object format(TemplateContext templateContext, Object data, Map parameters) {
@SuppressWarnings("unchecked")
List allReplies = (List) data;
- Map> postSones = new HashMap>();
- Map> postReplies = new HashMap>();
+ Map> postSones = new HashMap<>();
+ Map> postReplies = new HashMap<>();
for (PostReply reply : allReplies) {
/*
* All replies from a new-reply notification have posts,
* ListNotificationFilters takes care of that.
*/
- Optional post = reply.getPost();
- Set sones = postSones.get(post.get());
+ Post post = reply.getPost().get();
+ Set sones = postSones.get(post);
if (sones == null) {
- sones = new HashSet();
- postSones.put(post.get(), sones);
+ sones = new HashSet<>();
+ postSones.put(post, sones);
}
sones.add(reply.getSone());
- Set replies = postReplies.get(post.get());
+ Set replies = postReplies.get(post);
if (replies == null) {
- replies = new HashSet();
- postReplies.put(post.get(), replies);
+ replies = new HashSet<>();
+ postReplies.put(post, replies);
}
replies.add(reply);
}
- Map>> result = new HashMap>>();
- for (Post post : postSones.keySet()) {
- if (result.containsKey(post)) {
- continue;
- }
- Map> postResult = new HashMap>();
- postResult.put("sones", postSones.get(post));
- postResult.put("replies", postReplies.get(post));
- result.put(post, postResult);
+ Map>> result = new HashMap<>();
+ for (Entry> postEntry : postSones.entrySet()) {
+ Map> postResult = new HashMap<>();
+ postResult.put("sones", postEntry.getValue());
+ postResult.put("replies", postReplies.get(postEntry.getKey()));
+ result.put(postEntry.getKey(), postResult);
}
return result;
}