package net.pterodactylus.sone.notify;
import static com.google.common.collect.FluentIterable.from;
+import static java.util.stream.Collectors.toList;
import java.util.ArrayList;
import java.util.Collection;
@Nonnull
private Optional<ListNotification<Post>> filterPostNotification(@Nonnull ListNotification<Post> postNotification,
@Nullable Sone currentSone) {
- List<Post> newPosts = from(postNotification.getElements()).filter(postVisibilityFilter.isVisible(currentSone)).toList();
+ List<Post> newPosts = postNotification.getElements().stream().filter(postVisibilityFilter.isVisible(currentSone)).collect(toList());
if (newPosts.isEmpty()) {
return Optional.absent();
}
package net.pterodactylus.sone.notify;
+import java.util.function.Predicate;
+
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nonnull;
import net.pterodactylus.sone.freenet.wot.Trust;
import net.pterodactylus.util.notify.Notification;
-import com.google.common.base.Predicate;
-
/**
* Filters {@link Notification}s involving {@link Post}s.
*/
@Nonnull
public Predicate<Post> isVisible(@Nullable final Sone currentSone) {
- return new Predicate<Post>() {
- @Override
- public boolean apply(@Nullable Post post) {
- return (post != null) && isPostVisible(currentSone, post);
- }
- };
+ return post -> (post != null) && isPostVisible(currentSone, post);
}
}
.addAll(newPostNotification.getElements())
.addAll(localPostNotification.getElements())
.build();
- return from(allNewPosts).filter(postVisibilityFilter.isVisible(currentSone)).toSet();
+ return allNewPosts.stream().filter(postVisibilityFilter.isVisible(currentSone)).collect(toSet());
}
@Nonnull
.flatMap { it.posts } +
soneRequest.core.getDirectedPosts(currentSone.id)
).distinct()
- .filter { postVisibilityFilter.isVisible(currentSone).apply(it) }
+ .filter { postVisibilityFilter.isVisible(currentSone).test(it) }
.sortedByDescending { it.time }
.let { posts ->
posts.paginate(soneRequest.core.preferences.postsPerPage)
@Test
fun `predicate will correctly recognize visible post`() {
val post = createPost(sone = localSone)
- assertThat(postVisibilityFilter.isVisible(null).apply(post), equalTo(true))
+ assertThat(postVisibilityFilter.isVisible(null).test(post), equalTo(true))
}
@Test
fun `predicate will correctly recognize not visible post`() {
val post = createPost(loaded = false)
- assertThat(postVisibilityFilter.isVisible(null).apply(post), equalTo(false))
+ assertThat(postVisibilityFilter.isVisible(null).test(post), equalTo(false))
}
}