🎨 Use Java’s Predicate in reply visibility filter
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 20 Jun 2020 12:48:22 +0000 (14:48 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 20 Jun 2020 12:50:00 +0000 (14:50 +0200)
src/main/java/net/pterodactylus/sone/notify/ListNotificationFilter.java
src/main/java/net/pterodactylus/sone/notify/ReplyVisibilityFilter.java
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/test/java/net/pterodactylus/sone/notify/ReplyVisibilityFilterTest.java

index f2da694..76bfbff 100644 (file)
@@ -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<ListNotification<PostReply>> filterNewReplyNotification(ListNotification<PostReply> newReplyNotification,
                        @Nonnull Sone currentSone) {
-               List<PostReply> newReplies = from(newReplyNotification.getElements()).filter(replyVisibilityFilter.isVisible(currentSone)).toList();
+               List<PostReply> newReplies = newReplyNotification.getElements().stream().filter(replyVisibilityFilter.isVisible(currentSone)).collect(toList());
                if (newReplies.isEmpty()) {
                        return Optional.absent();
                }
index 5e3e16d..67a8d7d 100644 (file)
@@ -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<PostReply> isVisible(@Nullable final Sone currentSone) {
-               return new Predicate<PostReply>() {
-                       @Override
-                       public boolean apply(@Nullable PostReply postReply) {
-                               return (postReply != null) && isReplyVisible(currentSone, postReply);
-                       }
-               };
+               return postReply -> (postReply != null) && isReplyVisible(currentSone, postReply);
        }
 
 }
index 96677db..69077ed 100644 (file)
@@ -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());
        }
 
        //
index 3f430be..1ba723b 100644 (file)
@@ -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));
        }
 
 }