From: David ‘Bombe’ Roden Date: Sat, 20 Jun 2020 18:49:59 +0000 (+0200) Subject: ♻️ Move predicate method into interface X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=30223db6e2ad13491be1b46c6c13b41fbcc3937f;p=Sone.git ♻️ Move predicate method into interface --- diff --git a/build.gradle b/build.gradle index d36b87c..d0b159c 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,7 @@ tasks.withType(JavaCompile) { tasks.withType(KotlinCompile) { kotlinOptions { jvmTarget = "1.8" + freeCompilerArgs += '-Xjvm-default=enable' } } diff --git a/src/main/java/net/pterodactylus/sone/notify/DefaultPostVisibilityFilter.java b/src/main/java/net/pterodactylus/sone/notify/DefaultPostVisibilityFilter.java index a1ecfb7..7479d31 100644 --- a/src/main/java/net/pterodactylus/sone/notify/DefaultPostVisibilityFilter.java +++ b/src/main/java/net/pterodactylus/sone/notify/DefaultPostVisibilityFilter.java @@ -1,9 +1,5 @@ package net.pterodactylus.sone.notify; -import java.util.function.Predicate; - -import static com.google.common.base.Preconditions.checkNotNull; - import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.inject.Singleton; @@ -53,7 +49,6 @@ public class DefaultPostVisibilityFilter implements PostVisibilityFilter { */ @Override public boolean isPostVisible(@Nullable Sone sone, @Nonnull Post post) { - checkNotNull(post, "post must not be null"); if (!post.isLoaded()) { return false; } @@ -83,10 +78,4 @@ public class DefaultPostVisibilityFilter implements PostVisibilityFilter { return post.getTime() <= System.currentTimeMillis(); } - @Override - @Nonnull - public Predicate isVisible(@Nullable final Sone currentSone) { - return post -> (post != null) && isPostVisible(currentSone, post); - } - } diff --git a/src/main/java/net/pterodactylus/sone/notify/PostVisibilityFilter.java b/src/main/java/net/pterodactylus/sone/notify/PostVisibilityFilter.java deleted file mode 100644 index 308074a..0000000 --- a/src/main/java/net/pterodactylus/sone/notify/PostVisibilityFilter.java +++ /dev/null @@ -1,20 +0,0 @@ -package net.pterodactylus.sone.notify; - -import java.util.function.Predicate; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import net.pterodactylus.sone.data.Post; -import net.pterodactylus.sone.data.Sone; - -import com.google.inject.ImplementedBy; - -@ImplementedBy(DefaultPostVisibilityFilter.class) -public interface PostVisibilityFilter { - - boolean isPostVisible(@Nullable Sone sone, @Nonnull Post post); - - @Nonnull - Predicate isVisible(@Nullable Sone currentSone); - -} diff --git a/src/main/kotlin/net/pterodactylus/sone/notify/PostVisibilityFilter.kt b/src/main/kotlin/net/pterodactylus/sone/notify/PostVisibilityFilter.kt new file mode 100644 index 0000000..64df7b8 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/notify/PostVisibilityFilter.kt @@ -0,0 +1,17 @@ +package net.pterodactylus.sone.notify + +import com.google.inject.ImplementedBy +import net.pterodactylus.sone.data.Post +import net.pterodactylus.sone.data.Sone +import java.util.function.Predicate + +@ImplementedBy(DefaultPostVisibilityFilter::class) +interface PostVisibilityFilter { + + fun isPostVisible(sone: Sone?, post: Post): Boolean + + @JvmDefault + fun isVisible(currentSone: Sone?): Predicate = + Predicate { p: Post? -> p != null && isPostVisible(currentSone, p) } + +} diff --git a/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationFilterTest.kt b/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationFilterTest.kt index 327732e..3a7f47f 100644 --- a/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationFilterTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/notify/ListNotificationFilterTest.kt @@ -215,7 +215,6 @@ private val showNoPosts = createPostVisibilityFilter { _, _ -> false } private fun createPostVisibilityFilter(visible: (Sone?, Post) -> Boolean) = object : PostVisibilityFilter { override fun isPostVisible(sone: Sone?, post: Post) = visible(sone, post) - override fun isVisible(currentSone: Sone?) = Predicate { p -> p != null && isPostVisible(currentSone, p) } } private fun matchThisReply(reply: PostReply) = createReplyVisibilityFilter(showAllPosts) { _, r -> r == reply }