Replace utils’ HashCode by Java’s hashCode().
[Sone.git] / src / main / java / net / pterodactylus / sone / web / ajax / GetStatusAjaxPage.java
index bb4eb3c..8657a6a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - GetStatusAjaxPage.java - Copyright © 2010–2012 David Roden
+ * Sone - GetStatusAjaxPage.java - Copyright © 2010–2013 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
@@ -19,6 +19,7 @@ package net.pterodactylus.sone.web.ajax;
 
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashSet;
@@ -32,12 +33,12 @@ import net.pterodactylus.sone.notify.ListNotificationFilters;
 import net.pterodactylus.sone.template.SoneAccessor;
 import net.pterodactylus.sone.web.WebInterface;
 import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.filter.Filter;
-import net.pterodactylus.util.filter.Filters;
 import net.pterodactylus.util.json.JsonArray;
 import net.pterodactylus.util.json.JsonObject;
 import net.pterodactylus.util.notify.Notification;
-import net.pterodactylus.util.object.HashCode;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
 
 /**
  * The “get status” AJAX handler returns all information that is necessary to
@@ -66,19 +67,14 @@ public class GetStatusAjaxPage extends JsonPage {
        @Override
        protected JsonObject createJsonObject(FreenetRequest request) {
                final Sone currentSone = getCurrentSone(request.getToadletContext(), false);
-               /* load Sones. */
-               boolean loadAllSones = Boolean.parseBoolean(request.getHttpRequest().getParam("loadAllSones", "false"));
+               /* load Sones. always return the status of the current Sone. */
                Set<Sone> sones = new HashSet<Sone>(Collections.singleton(getCurrentSone(request.getToadletContext(), false)));
-               if (loadAllSones) {
-                       sones.addAll(webInterface.getCore().getSones());
-               } else {
-                       String loadSoneIds = request.getHttpRequest().getParam("soneIds");
-                       if (loadSoneIds.length() > 0) {
-                               String[] soneIds = loadSoneIds.split(",");
-                               for (String soneId : soneIds) {
-                                       /* just add it, we skip null further down. */
-                                       sones.add(webInterface.getCore().getSone(soneId, false));
-                               }
+               String loadSoneIds = request.getHttpRequest().getParam("soneIds");
+               if (loadSoneIds.length() > 0) {
+                       String[] soneIds = loadSoneIds.split(",");
+                       for (String soneId : soneIds) {
+                               /* just add it, we skip null further down. */
+                               sones.add(webInterface.getCore().getSone(soneId, false));
                        }
                }
                JsonArray jsonSones = new JsonArray();
@@ -91,14 +87,14 @@ public class GetStatusAjaxPage extends JsonPage {
                }
                /* load notifications. */
                List<Notification> notifications = ListNotificationFilters.filterNotifications(webInterface.getNotifications().getNotifications(), currentSone);
-               int notificationHash = HashCode.hashCode(notifications);
+               Collections.sort(notifications, Notification.CREATED_TIME_SORTER);
                /* load new posts. */
-               Set<Post> newPosts = webInterface.getNewPosts();
+               Collection<Post> newPosts = webInterface.getNewPosts();
                if (currentSone != null) {
-                       newPosts = Filters.filteredSet(newPosts, new Filter<Post>() {
+                       newPosts = Collections2.filter(newPosts, new Predicate<Post>() {
 
                                @Override
-                               public boolean filterObject(Post post) {
+                               public boolean apply(Post post) {
                                        return ListNotificationFilters.isPostVisible(currentSone, post);
                                }
 
@@ -114,22 +110,22 @@ public class GetStatusAjaxPage extends JsonPage {
                        jsonPosts.add(jsonPost);
                }
                /* load new replies. */
-               Set<PostReply> newReplies = webInterface.getNewReplies();
+               Collection<PostReply> newReplies = webInterface.getNewReplies();
                if (currentSone != null) {
-                       newReplies = Filters.filteredSet(newReplies, new Filter<PostReply>() {
+                       newReplies = Collections2.filter(newReplies, new Predicate<PostReply>() {
 
                                @Override
-                               public boolean filterObject(PostReply reply) {
+                               public boolean apply(PostReply reply) {
                                        return ListNotificationFilters.isReplyVisible(currentSone, reply);
                                }
 
                        });
                }
                /* remove replies to unknown posts. */
-               newReplies = Filters.filteredSet(newReplies, new Filter<PostReply>() {
+               newReplies = Collections2.filter(newReplies, new Predicate<PostReply>() {
 
                        @Override
-                       public boolean filterObject(PostReply reply) {
+                       public boolean apply(PostReply reply) {
                                return (reply.getPost() != null) && (reply.getPost().getSone() != null);
                        }
                });
@@ -142,7 +138,7 @@ public class GetStatusAjaxPage extends JsonPage {
                        jsonReply.put("postSone", reply.getPost().getSone().getId());
                        jsonReplies.add(jsonReply);
                }
-               return createSuccessJsonObject().put("loggedIn", currentSone != null).put("options", createJsonOptions(currentSone)).put("sones", jsonSones).put("notificationHash", notificationHash).put("newPosts", jsonPosts).put("newReplies", jsonReplies);
+               return createSuccessJsonObject().put("loggedIn", currentSone != null).put("options", createJsonOptions(currentSone)).put("sones", jsonSones).put("notificationHash", notifications.hashCode()).put("newPosts", jsonPosts).put("newReplies", jsonReplies);
        }
 
        /**
@@ -197,7 +193,7 @@ public class GetStatusAjaxPage extends JsonPage {
         *            The current Sone (may be {@code null})
         * @return The current options
         */
-       private JsonObject createJsonOptions(Sone currentSone) {
+       private static JsonObject createJsonOptions(Sone currentSone) {
                JsonObject options = new JsonObject();
                if (currentSone != null) {
                        options.put("ShowNotification/NewSones", currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").get());