/*
- * Sone - NewPage.java - Copyright © 2012 David Roden
+ * Sone - NewPage.java - Copyright © 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
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.pterodactylus.sone.notify.ListNotificationFilters;
import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.util.collection.Pagination;
-import net.pterodactylus.util.number.Numbers;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
+import com.google.common.base.Optional;
+import com.google.common.primitives.Ints;
+
/**
* Page that displays all new posts and replies. The posts are filtered using
* {@link ListNotificationFilters#filterPosts(java.util.Collection, net.pterodactylus.sone.data.Sone)}
//
/**
- * {@inherit}
+ * {@inheritDoc}
*/
@Override
protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
super.processTemplate(request, templateContext);
/* collect new elements from notifications. */
- Set<Post> posts = webInterface.getNewPosts();
+ Set<Post> posts = new HashSet<Post>(webInterface.getNewPosts());
for (PostReply reply : webInterface.getNewReplies()) {
posts.add(reply.getPost());
}
Collections.sort(sortedPosts, Post.TIME_COMPARATOR);
/* paginate them. */
- Pagination<Post> pagination = new Pagination<Post>(sortedPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0));
+ Pagination<Post> pagination = new Pagination<Post>(sortedPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Optional.fromNullable(Ints.tryParse(request.getHttpRequest().getParam("page"))).or(0));
templateContext.set("pagination", pagination);
templateContext.set("posts", pagination.getItems());
}