X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FSearchPage.java;h=002e4f2903a0e79fc8ab36a2bd38fcddc6178783;hb=26dbc1f7ba2c4243d8cc07986b0e943a2238ea08;hp=0f12abff77de543cfa29aa462a9481d28426096a;hpb=61fea0173ef87542cae35247e6356ef36f2664d3;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/SearchPage.java b/src/main/java/net/pterodactylus/sone/web/SearchPage.java index 0f12abf..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); @@ -346,7 +347,7 @@ public class SearchPage extends SoneTemplatePage { */ private String getReplyPostId(String phrase) { String replyId = phrase.startsWith("reply://") ? phrase.substring(8) : phrase; - return (webInterface.getCore().getReply(replyId, false) != null) ? webInterface.getCore().getReply(replyId, false).getPost().getId() : null; + return (webInterface.getCore().getPostReply(replyId, false) != null) ? webInterface.getCore().getPostReply(replyId, false).getPost().getId() : null; } /** @@ -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; }