tasks.withType(KotlinCompile) {
kotlinOptions {
jvmTarget = "1.8"
+ freeCompilerArgs += '-Xjvm-default=enable'
}
}
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;
*/
@Override
public boolean isPostVisible(@Nullable Sone sone, @Nonnull Post post) {
- checkNotNull(post, "post must not be null");
if (!post.isLoaded()) {
return false;
}
return post.getTime() <= System.currentTimeMillis();
}
- @Override
- @Nonnull
- public Predicate<Post> isVisible(@Nullable final Sone currentSone) {
- return post -> (post != null) && isPostVisible(currentSone, post);
- }
-
}
+++ /dev/null
-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<Post> isVisible(@Nullable Sone currentSone);
-
-}
--- /dev/null
+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<Post?> =
+ Predicate { p: Post? -> p != null && isPostVisible(currentSone, p) }
+
+}
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<Post> { p -> p != null && isPostVisible(currentSone, p) }
}
private fun matchThisReply(reply: PostReply) = createReplyVisibilityFilter(showAllPosts) { _, r -> r == reply }