From 067e4e19aad56f0c6de0d536f5de0bdefcf41b87 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 28 Jun 2020 21:11:20 +0200 Subject: [PATCH] =?utf8?q?=E2=99=BB=EF=B8=8F=20Supply=20default=20implemen?= =?utf8?q?tation=20for=20predicate?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../net/pterodactylus/sone/notify/DefaultReplyVisibilityFilter.java | 6 ------ .../java/net/pterodactylus/sone/notify/ReplyVisibilityFilter.java | 4 +++- src/test/kotlin/net/pterodactylus/sone/notify/Testing.kt | 3 +-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/notify/DefaultReplyVisibilityFilter.java b/src/main/java/net/pterodactylus/sone/notify/DefaultReplyVisibilityFilter.java index 0b891af..ec99cbe 100644 --- a/src/main/java/net/pterodactylus/sone/notify/DefaultReplyVisibilityFilter.java +++ b/src/main/java/net/pterodactylus/sone/notify/DefaultReplyVisibilityFilter.java @@ -59,10 +59,4 @@ public class DefaultReplyVisibilityFilter implements ReplyVisibilityFilter { return reply.getTime() <= System.currentTimeMillis(); } - @Nonnull - @Override - public Predicate isVisible(@Nullable final Sone currentSone) { - return postReply -> (postReply != null) && isReplyVisible(currentSone, postReply); - } - } diff --git a/src/main/java/net/pterodactylus/sone/notify/ReplyVisibilityFilter.java b/src/main/java/net/pterodactylus/sone/notify/ReplyVisibilityFilter.java index cd282b7..4091dd3 100644 --- a/src/main/java/net/pterodactylus/sone/notify/ReplyVisibilityFilter.java +++ b/src/main/java/net/pterodactylus/sone/notify/ReplyVisibilityFilter.java @@ -14,6 +14,8 @@ public interface ReplyVisibilityFilter { boolean isReplyVisible(@Nullable Sone sone, @Nonnull PostReply reply); - Predicate isVisible(@Nullable final Sone currentSone); + default Predicate isVisible(@Nullable final Sone currentSone) { + return reply -> (reply != null) && isReplyVisible(currentSone, reply); + } } diff --git a/src/test/kotlin/net/pterodactylus/sone/notify/Testing.kt b/src/test/kotlin/net/pterodactylus/sone/notify/Testing.kt index 381ded4..e7103c6 100644 --- a/src/test/kotlin/net/pterodactylus/sone/notify/Testing.kt +++ b/src/test/kotlin/net/pterodactylus/sone/notify/Testing.kt @@ -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 { r -> r != null && isReplyVisible(currentSone, r) } } -- 2.7.4