♻️ Supply default implementation for predicate
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 28 Jun 2020 19:11:20 +0000 (21:11 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 28 Jun 2020 19:11:20 +0000 (21:11 +0200)
src/main/java/net/pterodactylus/sone/notify/DefaultReplyVisibilityFilter.java
src/main/java/net/pterodactylus/sone/notify/ReplyVisibilityFilter.java
src/test/kotlin/net/pterodactylus/sone/notify/Testing.kt

index 0b891af..ec99cbe 100644 (file)
@@ -59,10 +59,4 @@ public class DefaultReplyVisibilityFilter implements ReplyVisibilityFilter {
                return reply.getTime() <= System.currentTimeMillis();
        }
 
-       @Nonnull
-       @Override
-       public Predicate<PostReply> isVisible(@Nullable final Sone currentSone) {
-               return postReply -> (postReply != null) && isReplyVisible(currentSone, postReply);
-       }
-
 }
index cd282b7..4091dd3 100644 (file)
@@ -14,6 +14,8 @@ public interface ReplyVisibilityFilter {
 
        boolean isReplyVisible(@Nullable Sone sone, @Nonnull PostReply reply);
 
-       Predicate<PostReply> isVisible(@Nullable final Sone currentSone);
+       default Predicate<PostReply> isVisible(@Nullable final Sone currentSone) {
+               return reply -> (reply != null) && isReplyVisible(currentSone, reply);
+       }
 
 }
index 381ded4..e7103c6 100644 (file)
@@ -17,7 +17,6 @@ fun matchThisReply(reply: PostReply) = createReplyVisibilityFilter(showAllPosts)
 val showAllReplies = createReplyVisibilityFilter(showAllPosts) { _, _ -> true }
 val showNoReplies = createReplyVisibilityFilter(showAllPosts) { _, _ -> false }
 
-private fun createReplyVisibilityFilter(postVisibilityFilter: PostVisibilityFilter, visible: (Sone?, PostReply) -> Boolean) = object : DefaultReplyVisibilityFilter(postVisibilityFilter) {
+private fun createReplyVisibilityFilter(postVisibilityFilter: PostVisibilityFilter, visible: (Sone?, PostReply) -> Boolean): ReplyVisibilityFilter = object : DefaultReplyVisibilityFilter(postVisibilityFilter) {
        override fun isReplyVisible(sone: Sone?, reply: PostReply) = visible(sone, reply)
-       override fun isVisible(currentSone: Sone?) = Predicate<PostReply> { r -> r != null && isReplyVisible(currentSone, r) }
 }