From: David ‘Bombe’ Roden Date: Wed, 16 Jan 2013 07:06:34 +0000 (+0100) Subject: Use Guava’s predicate instead of utils’ filter. X-Git-Tag: 0.8.5^2~3^2~132 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=26dbc1f7ba2c4243d8cc07986b0e943a2238ea08 Use Guava’s predicate instead of utils’ filter. --- diff --git a/src/main/java/net/pterodactylus/sone/data/Post.java b/src/main/java/net/pterodactylus/sone/data/Post.java index f171475..e68846a 100644 --- a/src/main/java/net/pterodactylus/sone/data/Post.java +++ b/src/main/java/net/pterodactylus/sone/data/Post.java @@ -19,7 +19,7 @@ package net.pterodactylus.sone.data; import java.util.Comparator; -import net.pterodactylus.util.collection.filter.Filter; +import com.google.common.base.Predicate; /** * A post is a short message that a user writes in his Sone to let other users @@ -40,10 +40,10 @@ public interface Post { }; /** Filter for posts with timestamps from the future. */ - public static final Filter FUTURE_POSTS_FILTER = new Filter() { + public static final Predicate FUTURE_POSTS_FILTER = new Predicate() { @Override - public boolean filterObject(Post post) { + public boolean apply(Post post) { return post.getTime() <= System.currentTimeMillis(); } diff --git a/src/main/java/net/pterodactylus/sone/data/Reply.java b/src/main/java/net/pterodactylus/sone/data/Reply.java index be60b88..f6e4a2c 100644 --- a/src/main/java/net/pterodactylus/sone/data/Reply.java +++ b/src/main/java/net/pterodactylus/sone/data/Reply.java @@ -20,7 +20,7 @@ package net.pterodactylus.sone.data; import java.util.Comparator; import java.util.UUID; -import net.pterodactylus.util.collection.filter.Filter; +import com.google.common.base.Predicate; /** * Abstract base class for all replies. @@ -45,13 +45,13 @@ public abstract class Reply> { }; /** Filter for replies with timestamps from the future. */ - public static final Filter> FUTURE_REPLY_FILTER = new Filter>() { + public static final Predicate> FUTURE_REPLY_FILTER = new Predicate>() { /** * {@inheritDoc} */ @Override - public boolean filterObject(Reply reply) { + public boolean apply(Reply reply) { return reply.getTime() <= System.currentTimeMillis(); } diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index 30dacd5..80032ad 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -32,9 +32,11 @@ import net.pterodactylus.sone.core.Options; import net.pterodactylus.sone.freenet.wot.Identity; import net.pterodactylus.sone.freenet.wot.OwnIdentity; import net.pterodactylus.sone.template.SoneAccessor; -import net.pterodactylus.util.collection.filter.Filter; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.validation.Validation; + +import com.google.common.base.Predicate; + import freenet.keys.FreenetURI; /** @@ -141,29 +143,29 @@ public class Sone implements Fingerprintable, Comparable { }; /** Filter to remove Sones that have not been downloaded. */ - public static final Filter EMPTY_SONE_FILTER = new Filter() { + public static final Predicate EMPTY_SONE_FILTER = new Predicate() { @Override - public boolean filterObject(Sone sone) { + public boolean apply(Sone sone) { return sone.getTime() != 0; } }; /** Filter that matches all {@link Sone#isLocal() local Sones}. */ - public static final Filter LOCAL_SONE_FILTER = new Filter() { + public static final Predicate LOCAL_SONE_FILTER = new Predicate() { @Override - public boolean filterObject(Sone sone) { + public boolean apply(Sone sone) { return sone.getIdentity() instanceof OwnIdentity; } }; /** Filter that matches Sones that have at least one album. */ - public static final Filter HAS_ALBUM_FILTER = new Filter() { + public static final Predicate HAS_ALBUM_FILTER = new Predicate() { @Override - public boolean filterObject(Sone sone) { + public boolean apply(Sone sone) { return !sone.getAlbums().isEmpty(); } }; diff --git a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java index 1eb488e..0b1e47b 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java +++ b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java @@ -32,7 +32,9 @@ import net.pterodactylus.sone.freenet.fcp.AbstractCommand; import net.pterodactylus.sone.freenet.fcp.Command; import net.pterodactylus.sone.freenet.fcp.FcpException; import net.pterodactylus.sone.template.SoneAccessor; -import net.pterodactylus.util.collection.filter.Filters; + +import com.google.common.collect.Collections2; + import freenet.node.FSParseException; import freenet.support.SimpleFieldSet; @@ -335,7 +337,7 @@ public abstract class AbstractSoneCommand extends AbstractCommand { String postPrefix = prefix + postIndex++; postBuilder.put(encodePost(post, postPrefix + ".", includeReplies)); if (includeReplies) { - postBuilder.put(encodeReplies(Filters.filteredList(core.getReplies(post), Reply.FUTURE_REPLY_FILTER), postPrefix + ".")); + postBuilder.put(encodeReplies(Collections2.filter(core.getReplies(post), Reply.FUTURE_REPLY_FILTER), postPrefix + ".")); } } diff --git a/src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java b/src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java index 781bed2..bec162f 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java +++ b/src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java @@ -18,16 +18,18 @@ package net.pterodactylus.sone.fcp; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; -import java.util.Set; import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.freenet.fcp.FcpException; -import net.pterodactylus.util.collection.filter.Filters; + +import com.google.common.collect.Collections2; + import freenet.support.SimpleFieldSet; import freenet.support.api.Bucket; @@ -58,7 +60,7 @@ public class GetPostFeedCommand extends AbstractSoneCommand { int startPost = getInt(parameters, "StartPost", 0); int maxPosts = getInt(parameters, "MaxPosts", -1); - Set allPosts = new HashSet(); + Collection allPosts = new HashSet(); allPosts.addAll(sone.getPosts()); for (String friendSoneId : sone.getFriends()) { if (!getCore().hasSone(friendSoneId)) { @@ -67,7 +69,7 @@ public class GetPostFeedCommand extends AbstractSoneCommand { allPosts.addAll(getCore().getSone(friendSoneId, false).getPosts()); } allPosts.addAll(getCore().getDirectedPosts(sone)); - allPosts = Filters.filteredSet(allPosts, Post.FUTURE_POSTS_FILTER); + allPosts = Collections2.filter(allPosts, Post.FUTURE_POSTS_FILTER); List sortedPosts = new ArrayList(allPosts); Collections.sort(sortedPosts, Post.TIME_COMPARATOR); diff --git a/src/main/java/net/pterodactylus/sone/template/PostAccessor.java b/src/main/java/net/pterodactylus/sone/template/PostAccessor.java index d05b074..6064017 100644 --- a/src/main/java/net/pterodactylus/sone/template/PostAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/PostAccessor.java @@ -21,10 +21,11 @@ import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.util.collection.filter.Filters; import net.pterodactylus.util.template.ReflectionAccessor; import net.pterodactylus.util.template.TemplateContext; +import com.google.common.collect.Collections2; + /** * Accessor for {@link Post} objects that adds additional properties: *
@@ -56,7 +57,7 @@ public class PostAccessor extends ReflectionAccessor { public Object get(TemplateContext templateContext, Object object, String member) { Post post = (Post) object; if ("replies".equals(member)) { - return Filters.filteredList(core.getReplies(post), Reply.FUTURE_REPLY_FILTER); + return Collections2.filter(core.getReplies(post), Reply.FUTURE_REPLY_FILTER); } else if (member.equals("likes")) { return core.getLikes(post); } else if (member.equals("liked")) { diff --git a/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java b/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java index 95dfd65..66f7236 100644 --- a/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java +++ b/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.web; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Set; @@ -25,12 +26,13 @@ import java.util.Set; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.collection.Pagination; -import net.pterodactylus.util.collection.filter.Filter; -import net.pterodactylus.util.collection.filter.Filters; import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import com.google.common.base.Predicate; +import com.google.common.collect.Collections2; + /** * Page that lets the user browse all his bookmarked posts. * @@ -61,10 +63,10 @@ public class BookmarksPage extends SoneTemplatePage { protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); Set allPosts = webInterface.getCore().getBookmarkedPosts(); - Set loadedPosts = Filters.filteredSet(allPosts, new Filter() { + Collection loadedPosts = Collections2.filter(allPosts, new Predicate() { @Override - public boolean filterObject(Post post) { + public boolean apply(Post post) { return post.getSone() != null; } }); diff --git a/src/main/java/net/pterodactylus/sone/web/IndexPage.java b/src/main/java/net/pterodactylus/sone/web/IndexPage.java index 8a5d1b5..baa5609 100644 --- a/src/main/java/net/pterodactylus/sone/web/IndexPage.java +++ b/src/main/java/net/pterodactylus/sone/web/IndexPage.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.web; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; @@ -26,12 +27,13 @@ import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.notify.ListNotificationFilters; import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.collection.Pagination; -import net.pterodactylus.util.collection.filter.Filter; -import net.pterodactylus.util.collection.filter.Filters; import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import com.google.common.base.Predicate; +import com.google.common.collect.Collections2; + /** * The index page shows the main page of Sone. This page will contain the posts * of all friends of the current user. @@ -61,7 +63,7 @@ public class IndexPage extends SoneTemplatePage { protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); final Sone currentSone = getCurrentSone(request.getToadletContext()); - List allPosts = new ArrayList(); + Collection allPosts = new ArrayList(); allPosts.addAll(currentSone.getPosts()); for (String friendSoneId : currentSone.getFriends()) { if (!webInterface.getCore().hasSone(friendSoneId)) { @@ -76,16 +78,17 @@ public class IndexPage extends SoneTemplatePage { } } } - allPosts = Filters.filteredList(allPosts, new Filter() { + allPosts = Collections2.filter(allPosts, new Predicate() { @Override - public boolean filterObject(Post post) { + public boolean apply(Post post) { return ListNotificationFilters.isPostVisible(currentSone, post); } }); - allPosts = Filters.filteredList(allPosts, Post.FUTURE_POSTS_FILTER); - Collections.sort(allPosts, Post.TIME_COMPARATOR); - Pagination pagination = new Pagination(allPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0)); + allPosts = Collections2.filter(allPosts, Post.FUTURE_POSTS_FILTER); + List sortedPosts = new ArrayList(allPosts); + Collections.sort(sortedPosts, Post.TIME_COMPARATOR); + Pagination pagination = new Pagination(sortedPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0)); templateContext.set("pagination", pagination); templateContext.set("posts", pagination.getItems()); } diff --git a/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java b/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java index 00568da..bc928c4 100644 --- a/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java +++ b/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.web; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; @@ -25,12 +26,14 @@ import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.collection.Pagination; import net.pterodactylus.util.collection.ReverseComparator; -import net.pterodactylus.util.collection.filter.Filter; -import net.pterodactylus.util.collection.filter.Filters; import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import com.google.common.collect.Collections2; + /** * This page shows all known Sones. * @@ -67,74 +70,77 @@ public class KnownSonesPage extends SoneTemplatePage { templateContext.set("order", (sortOrder != null) ? sortOrder : "asc"); templateContext.set("filter", filter); final Sone currentSone = getCurrentSone(request.getToadletContext(), false); - List knownSones = Filters.filteredList(new ArrayList(webInterface.getCore().getSones()), Sone.EMPTY_SONE_FILTER); + Collection knownSones = Collections2.filter(webInterface.getCore().getSones(), Sone.EMPTY_SONE_FILTER); if ((currentSone != null) && "followed".equals(filter)) { - knownSones = Filters.filteredList(knownSones, new Filter() { + knownSones = Collections2.filter(knownSones, new Predicate() { @Override - public boolean filterObject(Sone sone) { + public boolean apply(Sone sone) { return currentSone.hasFriend(sone.getId()); } }); } else if ((currentSone != null) && "not-followed".equals(filter)) { - knownSones = Filters.filteredList(knownSones, new Filter() { + knownSones = Collections2.filter(knownSones, new Predicate() { @Override - public boolean filterObject(Sone sone) { + public boolean apply(Sone sone) { return !currentSone.hasFriend(sone.getId()); } }); } else if ("new".equals(filter)) { - knownSones = Filters.filteredList(knownSones, new Filter() { + knownSones = Collections2.filter(knownSones, new Predicate() { + /** * {@inheritDoc} */ @Override - public boolean filterObject(Sone sone) { + public boolean apply(Sone sone) { return !sone.isKnown(); } }); } else if ("not-new".equals(filter)) { - knownSones = Filters.filteredList(knownSones, new Filter() { + knownSones = Collections2.filter(knownSones, new Predicate() { + /** * {@inheritDoc} */ @Override - public boolean filterObject(Sone sone) { + public boolean apply(Sone sone) { return sone.isKnown(); } }); } else if ("own".equals(filter)) { - knownSones = Filters.filteredList(knownSones, Sone.LOCAL_SONE_FILTER); + knownSones = Collections2.filter(knownSones, Sone.LOCAL_SONE_FILTER); } else if ("not-own".equals(filter)) { - knownSones = Filters.filteredList(knownSones, Filters.reverseFilter(Sone.LOCAL_SONE_FILTER)); + knownSones = Collections2.filter(knownSones, Predicates.not(Sone.LOCAL_SONE_FILTER)); } + List sortedSones = new ArrayList(knownSones); if ("activity".equals(sortField)) { if ("asc".equals(sortOrder)) { - Collections.sort(knownSones, new ReverseComparator(Sone.LAST_ACTIVITY_COMPARATOR)); + Collections.sort(sortedSones, new ReverseComparator(Sone.LAST_ACTIVITY_COMPARATOR)); } else { - Collections.sort(knownSones, Sone.LAST_ACTIVITY_COMPARATOR); + Collections.sort(sortedSones, Sone.LAST_ACTIVITY_COMPARATOR); } } else if ("posts".equals(sortField)) { if ("asc".equals(sortOrder)) { - Collections.sort(knownSones, new ReverseComparator(Sone.POST_COUNT_COMPARATOR)); + Collections.sort(sortedSones, new ReverseComparator(Sone.POST_COUNT_COMPARATOR)); } else { - Collections.sort(knownSones, Sone.POST_COUNT_COMPARATOR); + Collections.sort(sortedSones, Sone.POST_COUNT_COMPARATOR); } } else if ("images".equals(sortField)) { if ("asc".equals(sortOrder)) { - Collections.sort(knownSones, new ReverseComparator(Sone.IMAGE_COUNT_COMPARATOR)); + Collections.sort(sortedSones, new ReverseComparator(Sone.IMAGE_COUNT_COMPARATOR)); } else { - Collections.sort(knownSones, Sone.IMAGE_COUNT_COMPARATOR); + Collections.sort(sortedSones, Sone.IMAGE_COUNT_COMPARATOR); } } else { if ("desc".equals(sortOrder)) { - Collections.sort(knownSones, new ReverseComparator(Sone.NICE_NAME_COMPARATOR)); + Collections.sort(sortedSones, new ReverseComparator(Sone.NICE_NAME_COMPARATOR)); } else { - Collections.sort(knownSones, Sone.NICE_NAME_COMPARATOR); + Collections.sort(sortedSones, Sone.NICE_NAME_COMPARATOR); } } - Pagination sonePagination = new Pagination(knownSones, 25).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0)); + Pagination sonePagination = new Pagination(sortedSones, 25).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0)); templateContext.set("pagination", sonePagination); templateContext.set("knownSones", sonePagination.getItems()); } diff --git a/src/main/java/net/pterodactylus/sone/web/SearchPage.java b/src/main/java/net/pterodactylus/sone/web/SearchPage.java index 6d300ed..002e4f2 100644 --- a/src/main/java/net/pterodactylus/sone/web/SearchPage.java +++ b/src/main/java/net/pterodactylus/sone/web/SearchPage.java @@ -42,8 +42,6 @@ import net.pterodactylus.util.cache.MemoryCache; import net.pterodactylus.util.cache.ValueRetriever; import net.pterodactylus.util.collection.Pagination; import net.pterodactylus.util.collection.TimedMap; -import net.pterodactylus.util.collection.filter.Filter; -import net.pterodactylus.util.collection.filter.Filters; import net.pterodactylus.util.collection.mapper.Mapper; import net.pterodactylus.util.collection.mapper.Mappers; import net.pterodactylus.util.logging.Logging; @@ -53,6 +51,9 @@ import net.pterodactylus.util.template.TemplateContext; import net.pterodactylus.util.text.StringEscaper; import net.pterodactylus.util.text.TextException; +import com.google.common.base.Predicate; +import com.google.common.collect.Collections2; + /** * This page lets the user search for posts and replies that contain certain * words. @@ -74,7 +75,7 @@ public class SearchPage extends SoneTemplatePage { for (Sone sone : webInterface.getCore().getSones()) { posts.addAll(sone.getPosts()); } - return new DefaultCacheItem>>(getHits(Filters.filteredSet(posts, Post.FUTURE_POSTS_FILTER), phrases, new PostStringGenerator())); + return new DefaultCacheItem>>(getHits(Collections2.filter(posts, Post.FUTURE_POSTS_FILTER), phrases, new PostStringGenerator())); } }, new TimedMap, CacheItem>>>(300000)); @@ -132,9 +133,9 @@ public class SearchPage extends SoneTemplatePage { } Set sones = webInterface.getCore().getSones(); - Set> soneHits = getHits(sones, phrases, SoneStringGenerator.COMPLETE_GENERATOR); + Collection> soneHits = getHits(sones, phrases, SoneStringGenerator.COMPLETE_GENERATOR); - Set> postHits; + Collection> postHits; try { postHits = hitCache.get(phrases); } catch (CacheException ce1) { @@ -144,8 +145,8 @@ public class SearchPage extends SoneTemplatePage { } /* now filter. */ - soneHits = Filters.filteredSet(soneHits, Hit.POSITIVE_FILTER); - postHits = Filters.filteredSet(postHits, Hit.POSITIVE_FILTER); + soneHits = Collections2.filter(soneHits, Hit.POSITIVE_FILTER); + postHits = Collections2.filter(postHits, Hit.POSITIVE_FILTER); /* now sort. */ List> sortedSoneHits = new ArrayList>(soneHits); @@ -472,7 +473,7 @@ public class SearchPage extends SoneTemplatePage { if (post.getRecipient() != null) { postString.append(' ').append(SoneStringGenerator.NAME_GENERATOR.generateString(post.getRecipient())); } - for (PostReply reply : Filters.filteredList(webInterface.getCore().getReplies(post), Reply.FUTURE_REPLY_FILTER)) { + for (PostReply reply : Collections2.filter(webInterface.getCore().getReplies(post), Reply.FUTURE_REPLY_FILTER)) { postString.append(' ').append(SoneStringGenerator.NAME_GENERATOR.generateString(reply.getSone())); postString.append(' ').append(reply.getText()); } @@ -582,10 +583,10 @@ public class SearchPage extends SoneTemplatePage { private static class Hit { /** Filter for {@link Hit}s with a score of more than 0. */ - public static final Filter> POSITIVE_FILTER = new Filter>() { + public static final Predicate> POSITIVE_FILTER = new Predicate>() { @Override - public boolean filterObject(Hit hit) { + public boolean apply(Hit hit) { return hit.getScore() > 0; } diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 20b1f82..436ed5f 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -104,7 +104,6 @@ import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.sone.web.page.PageToadlet; import net.pterodactylus.sone.web.page.PageToadletFactory; import net.pterodactylus.util.collection.SetBuilder; -import net.pterodactylus.util.collection.filter.Filters; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.notify.Notification; import net.pterodactylus.util.notify.NotificationManager; @@ -132,6 +131,7 @@ import net.pterodactylus.util.web.RedirectPage; import net.pterodactylus.util.web.StaticPage; import net.pterodactylus.util.web.TemplatePage; +import com.google.common.collect.Collections2; import com.google.inject.Inject; import freenet.clients.http.SessionManager; @@ -737,7 +737,7 @@ public class WebInterface implements CoreListener { * The text to parse * @return All mentioned local Sones */ - private Set getMentionedSones(String text) { + private Collection getMentionedSones(String text) { /* we need no context to find mentioned Sones. */ Set mentionedSones = new HashSet(); try { @@ -749,7 +749,7 @@ public class WebInterface implements CoreListener { } catch (IOException ioe1) { logger.log(Level.WARNING, String.format("Could not parse post text: %s", text), ioe1); } - return Filters.filteredSet(mentionedSones, Sone.LOCAL_SONE_FILTER); + return Collections2.filter(mentionedSones, Sone.LOCAL_SONE_FILTER); } /** diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java index 4c61f89..b1ac58a 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java @@ -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,13 +33,14 @@ 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.collection.filter.Filter; -import net.pterodactylus.util.collection.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 * update the web interface in real-time. @@ -89,12 +91,12 @@ public class GetStatusAjaxPage extends JsonPage { Collections.sort(notifications, Notification.CREATED_TIME_SORTER); int notificationHash = HashCode.hashCode(notifications); /* load new posts. */ - Set newPosts = webInterface.getNewPosts(); + Collection newPosts = webInterface.getNewPosts(); if (currentSone != null) { - newPosts = Filters.filteredSet(newPosts, new Filter() { + newPosts = Collections2.filter(newPosts, new Predicate() { @Override - public boolean filterObject(Post post) { + public boolean apply(Post post) { return ListNotificationFilters.isPostVisible(currentSone, post); } @@ -110,22 +112,22 @@ public class GetStatusAjaxPage extends JsonPage { jsonPosts.add(jsonPost); } /* load new replies. */ - Set newReplies = webInterface.getNewReplies(); + Collection newReplies = webInterface.getNewReplies(); if (currentSone != null) { - newReplies = Filters.filteredSet(newReplies, new Filter() { + newReplies = Collections2.filter(newReplies, new Predicate() { @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() { + newReplies = Collections2.filter(newReplies, new Predicate() { @Override - public boolean filterObject(PostReply reply) { + public boolean apply(PostReply reply) { return (reply.getPost() != null) && (reply.getPost().getSone() != null); } });