package net.pterodactylus.sone.notify;
-import static com.google.common.collect.FluentIterable.from;
import static java.util.stream.Collectors.toList;
import java.util.ArrayList;
*/
private Optional<ListNotification<PostReply>> filterNewReplyNotification(ListNotification<PostReply> newReplyNotification,
@Nonnull Sone currentSone) {
- List<PostReply> newReplies = from(newReplyNotification.getElements()).filter(replyVisibilityFilter.isVisible(currentSone)).toList();
+ List<PostReply> newReplies = newReplyNotification.getElements().stream().filter(replyVisibilityFilter.isVisible(currentSone)).collect(toList());
if (newReplies.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.data.Sone;
import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
/**
* Filter that checks a {@link PostReply} for visibility.
@Nonnull
public Predicate<PostReply> isVisible(@Nullable final Sone currentSone) {
- return new Predicate<PostReply>() {
- @Override
- public boolean apply(@Nullable PostReply postReply) {
- return (postReply != null) && isReplyVisible(currentSone, postReply);
- }
- };
+ return postReply -> (postReply != null) && isReplyVisible(currentSone, postReply);
}
}
package net.pterodactylus.sone.web;
-import static com.google.common.collect.FluentIterable.from;
import static java.util.logging.Logger.getLogger;
+import static java.util.stream.Collectors.toSet;
import java.util.Collection;
import java.util.Set;
.addAll(newReplyNotification.getElements())
.addAll(localReplyNotification.getElements())
.build();
- return from(allNewReplies).filter(replyVisibilityFilter.isVisible(currentSone)).toSet();
+ return allNewReplies.stream().filter(replyVisibilityFilter.isVisible(currentSone)).collect(toSet());
}
//
@Test
public void predicateCorrectlyRecognizesVisibleReply() {
makePostPresentAndVisible();
- assertThat(replyVisibilityFilter.isVisible(localSone).apply(postReply), is(true));
+ assertThat(replyVisibilityFilter.isVisible(localSone).test(postReply), is(true));
}
@Test
public void predicateCorrectlyRecognizesNotVisibleReply() {
makePostPresentAndVisible();
makeReplyComeFromFuture();
- assertThat(replyVisibilityFilter.isVisible(localSone).apply(postReply), is(false));
+ assertThat(replyVisibilityFilter.isVisible(localSone).test(postReply), is(false));
}
}