X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fnotify%2FListNotificationFilter.java;h=76bfbff7766be421bd803c2bdf83bca05a239184;hb=a5743ce8177323159e4d1828dced6021d27c4d62;hp=f3c93053c5feaad8cbb7d28a3937713ffd8a0a20;hpb=d36aa88de57f1492db61e3f6cb4daeeceab1904e;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilter.java b/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilter.java
index f3c9305..76bfbff 100644
--- a/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilter.java
+++ b/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilter.java
@@ -1,5 +1,5 @@
/*
- * Sone - ListNotificationFilters.java - Copyright © 2010â2015 David Roden
+ * Sone - ListNotificationFilter.java - Copyright © 2010â2020 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
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;
@@ -36,8 +36,6 @@ import com.google.common.base.Optional;
/**
* Filter for {@link ListNotification}s.
- *
- * @author David âBombeâ Roden
*/
@Singleton
public class ListNotificationFilter {
@@ -67,7 +65,7 @@ public class ListNotificationFilter {
*/
@SuppressWarnings("unchecked")
public List filterNotifications(Collection extends Notification> notifications, Sone currentSone) {
- List filteredNotifications = new ArrayList();
+ List filteredNotifications = new ArrayList<>();
for (Notification notification : notifications) {
if (notification.getId().equals("new-sone-notification")) {
if ((currentSone != null) && !currentSone.getOptions().isShowNewSoneNotifications()) {
@@ -81,7 +79,7 @@ public class ListNotificationFilter {
if (!currentSone.getOptions().isShowNewPostNotifications()) {
continue;
}
- Optional> filteredNotification = filterNewPostNotification((ListNotification) notification, currentSone);
+ Optional> filteredNotification = filterPostNotification((ListNotification) notification, currentSone);
if (filteredNotification.isPresent()) {
filteredNotifications.add(filteredNotification.get());
}
@@ -98,7 +96,7 @@ public class ListNotificationFilter {
filteredNotifications.add(filteredNotification.get());
}
} else if (notification.getId().equals("mention-notification")) {
- Optional> filteredNotification = filterNewPostNotification((ListNotification) notification, null);
+ Optional> filteredNotification = filterPostNotification((ListNotification) notification, null);
if (filteredNotification.isPresent()) {
filteredNotifications.add(filteredNotification.get());
}
@@ -119,16 +117,16 @@ public class ListNotificationFilter {
* @return The filtered post notification, or {@link Optional#absent()} if the notification should be removed
*/
@Nonnull
- private Optional> filterNewPostNotification(@Nonnull ListNotification postNotification,
+ private Optional> filterPostNotification(@Nonnull ListNotification postNotification,
@Nullable Sone currentSone) {
- List newPosts = from(postNotification.getElements()).filter(postVisibilityFilter.isVisible(currentSone)).toList();
+ List newPosts = postNotification.getElements().stream().filter(postVisibilityFilter.isVisible(currentSone)).collect(toList());
if (newPosts.isEmpty()) {
return Optional.absent();
}
if (newPosts.size() == postNotification.getElements().size()) {
return Optional.of(postNotification);
}
- ListNotification filteredNotification = new ListNotification(postNotification);
+ ListNotification filteredNotification = new ListNotification<>(postNotification);
filteredNotification.setElements(newPosts);
filteredNotification.setLastUpdateTime(postNotification.getLastUpdatedTime());
return Optional.of(filteredNotification);
@@ -150,14 +148,14 @@ public class ListNotificationFilter {
*/
private Optional> filterNewReplyNotification(ListNotification newReplyNotification,
@Nonnull Sone currentSone) {
- List newReplies = from(newReplyNotification.getElements()).filter(replyVisibilityFilter.isVisible(currentSone)).toList();
+ List newReplies = newReplyNotification.getElements().stream().filter(replyVisibilityFilter.isVisible(currentSone)).collect(toList());
if (newReplies.isEmpty()) {
return Optional.absent();
}
if (newReplies.size() == newReplyNotification.getElements().size()) {
return Optional.of(newReplyNotification);
}
- ListNotification filteredNotification = new ListNotification(newReplyNotification);
+ ListNotification filteredNotification = new ListNotification<>(newReplyNotification);
filteredNotification.setElements(newReplies);
filteredNotification.setLastUpdateTime(newReplyNotification.getLastUpdatedTime());
return Optional.of(filteredNotification);