From a5743ce8177323159e4d1828dced6021d27c4d62 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 20 Jun 2020 14:48:22 +0200 Subject: [PATCH] =?utf8?q?=F0=9F=8E=A8=20Use=20Java=E2=80=99s=20Predicate?= =?utf8?q?=20in=20reply=20visibility=20filter?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../net/pterodactylus/sone/notify/ListNotificationFilter.java | 3 +-- .../net/pterodactylus/sone/notify/ReplyVisibilityFilter.java | 10 +++------- src/main/java/net/pterodactylus/sone/web/WebInterface.java | 4 ++-- .../pterodactylus/sone/notify/ReplyVisibilityFilterTest.java | 4 ++-- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilter.java b/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilter.java index f2da694..76bfbff 100644 --- a/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilter.java +++ b/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilter.java @@ -17,7 +17,6 @@ package net.pterodactylus.sone.notify; -import static com.google.common.collect.FluentIterable.from; import static java.util.stream.Collectors.toList; import java.util.ArrayList; @@ -149,7 +148,7 @@ public class ListNotificationFilter { */ private Optional> filterNewReplyNotification(ListNotification newReplyNotification, @Nonnull Sone currentSone) { - List newReplies = from(newReplyNotification.getElements()).filter(replyVisibilityFilter.isVisible(currentSone)).toList(); + List newReplies = newReplyNotification.getElements().stream().filter(replyVisibilityFilter.isVisible(currentSone)).collect(toList()); if (newReplies.isEmpty()) { return Optional.absent(); } diff --git a/src/main/java/net/pterodactylus/sone/notify/ReplyVisibilityFilter.java b/src/main/java/net/pterodactylus/sone/notify/ReplyVisibilityFilter.java index 5e3e16d..67a8d7d 100644 --- a/src/main/java/net/pterodactylus/sone/notify/ReplyVisibilityFilter.java +++ b/src/main/java/net/pterodactylus/sone/notify/ReplyVisibilityFilter.java @@ -1,5 +1,7 @@ package net.pterodactylus.sone.notify; +import java.util.function.Predicate; + import static com.google.common.base.Preconditions.checkNotNull; import javax.annotation.Nonnull; @@ -12,7 +14,6 @@ import net.pterodactylus.sone.data.PostReply; import net.pterodactylus.sone.data.Sone; import com.google.common.base.Optional; -import com.google.common.base.Predicate; /** * Filter that checks a {@link PostReply} for visibility. @@ -59,12 +60,7 @@ public class ReplyVisibilityFilter { @Nonnull public Predicate isVisible(@Nullable final Sone currentSone) { - return new Predicate() { - @Override - public boolean apply(@Nullable PostReply postReply) { - return (postReply != null) && isReplyVisible(currentSone, postReply); - } - }; + return postReply -> (postReply != null) && isReplyVisible(currentSone, postReply); } } diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 96677db..69077ed 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -17,8 +17,8 @@ package net.pterodactylus.sone.web; -import static com.google.common.collect.FluentIterable.from; import static java.util.logging.Logger.getLogger; +import static java.util.stream.Collectors.toSet; import java.util.Collection; import java.util.Set; @@ -273,7 +273,7 @@ public class WebInterface implements SessionProvider { .addAll(newReplyNotification.getElements()) .addAll(localReplyNotification.getElements()) .build(); - return from(allNewReplies).filter(replyVisibilityFilter.isVisible(currentSone)).toSet(); + return allNewReplies.stream().filter(replyVisibilityFilter.isVisible(currentSone)).collect(toSet()); } // diff --git a/src/test/java/net/pterodactylus/sone/notify/ReplyVisibilityFilterTest.java b/src/test/java/net/pterodactylus/sone/notify/ReplyVisibilityFilterTest.java index 3f430be..1ba723b 100644 --- a/src/test/java/net/pterodactylus/sone/notify/ReplyVisibilityFilterTest.java +++ b/src/test/java/net/pterodactylus/sone/notify/ReplyVisibilityFilterTest.java @@ -91,14 +91,14 @@ public class ReplyVisibilityFilterTest { @Test public void predicateCorrectlyRecognizesVisibleReply() { makePostPresentAndVisible(); - assertThat(replyVisibilityFilter.isVisible(localSone).apply(postReply), is(true)); + assertThat(replyVisibilityFilter.isVisible(localSone).test(postReply), is(true)); } @Test public void predicateCorrectlyRecognizesNotVisibleReply() { makePostPresentAndVisible(); makeReplyComeFromFuture(); - assertThat(replyVisibilityFilter.isVisible(localSone).apply(postReply), is(false)); + assertThat(replyVisibilityFilter.isVisible(localSone).test(postReply), is(false)); } } -- 2.7.4