From: David ‘Bombe’ Roden Date: Sat, 20 Jun 2020 12:48:22 +0000 (+0200) Subject: 🎨 Use Java’s Predicate in reply visibility filter X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=a5743ce8177323159e4d1828dced6021d27c4d62;p=Sone.git 🎨 Use Java’s Predicate in reply visibility filter --- 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)); } }