Use list notification.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 17 Nov 2010 20:45:27 +0000 (21:45 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 17 Nov 2010 20:45:27 +0000 (21:45 +0100)
src/main/java/net/pterodactylus/sone/notify/NewPostNotification.java [deleted file]
src/main/java/net/pterodactylus/sone/notify/NewReplyNotification.java [deleted file]
src/main/java/net/pterodactylus/sone/notify/NewSoneNotification.java [deleted file]
src/main/java/net/pterodactylus/sone/web/WebInterface.java

diff --git a/src/main/java/net/pterodactylus/sone/notify/NewPostNotification.java b/src/main/java/net/pterodactylus/sone/notify/NewPostNotification.java
deleted file mode 100644 (file)
index 5a5f49f..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Sone - NewPostNotification.java - Copyright © 2010 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.notify;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.util.notify.TemplateNotification;
-import net.pterodactylus.util.template.Template;
-
-/**
- * Notification that signals that new {@link Post}s have been discovered.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class NewPostNotification extends TemplateNotification {
-
-       /** The new posts. */
-       private List<Post> newPosts = Collections.synchronizedList(new ArrayList<Post>());
-
-       /**
-        * Creates a new “new post discovered” notification.
-        *
-        * @param template
-        *            The template to render
-        */
-       public NewPostNotification(Template template) {
-               super(template);
-               template.set("posts", newPosts);
-       }
-
-       //
-       // ACCESSORS
-       //
-
-       /**
-        * Returns whether there are any new posts.
-        *
-        * @return {@code true} if there are no new posts, {@code false} if there
-        *         are new posts
-        */
-       public boolean isEmpty() {
-               return newPosts.isEmpty();
-       }
-
-       /**
-        * Adds a discovered post.
-        *
-        * @param post
-        *            The new post
-        */
-       public void addPost(Post post) {
-               newPosts.add(post);
-               touch();
-       }
-
-       /**
-        * Removes the given post from the list of new posts.
-        *
-        * @param post
-        *            The post to remove
-        */
-       public void removePost(Post post) {
-               newPosts.remove(post);
-               touch();
-       }
-
-       //
-       // ABSTRACTNOTIFICATION METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public void dismiss() {
-               super.dismiss();
-               newPosts.clear();
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/notify/NewReplyNotification.java b/src/main/java/net/pterodactylus/sone/notify/NewReplyNotification.java
deleted file mode 100644 (file)
index 1b33245..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Sone - NewReplyNotification.java - Copyright © 2010 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.notify;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import net.pterodactylus.sone.data.Reply;
-import net.pterodactylus.util.notify.TemplateNotification;
-import net.pterodactylus.util.template.Template;
-
-/**
- * Notification that signals that new {@link Reply}s have been discovered.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class NewReplyNotification extends TemplateNotification {
-
-       /** The new replies. */
-       private final List<Reply> newReplies = Collections.synchronizedList(new ArrayList<Reply>());
-
-       /**
-        * Creates a “new reply” notification.
-        *
-        * @param template
-        *            The template to render
-        */
-       public NewReplyNotification(Template template) {
-               super(template);
-               template.set("replies", newReplies);
-       }
-
-       //
-       // ACCESSORS
-       //
-
-       /**
-        * Returns whether there are any new replies.
-        *
-        * @return {@code true} if there are no new replies, {@code false} if there
-        *         are new replies
-        */
-       public boolean isEmpty() {
-               return newReplies.isEmpty();
-       }
-
-       /**
-        * Adds a discovered reply.
-        *
-        * @param reply
-        *            The new reply
-        */
-       public void addReply(Reply reply) {
-               newReplies.add(reply);
-               touch();
-       }
-
-       /**
-        * Removes the given reply from the list of new replies.
-        *
-        * @param reply
-        *            The reply to remove
-        */
-       public void removeReply(Reply reply) {
-               newReplies.remove(reply);
-               touch();
-       }
-
-       //
-       // ABSTRACTNOTIFICATION METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public void dismiss() {
-               super.dismiss();
-               newReplies.clear();
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/notify/NewSoneNotification.java b/src/main/java/net/pterodactylus/sone/notify/NewSoneNotification.java
deleted file mode 100644 (file)
index f3388b1..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Sone - NewSoneNotification.java - Copyright © 2010 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.notify;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.util.notify.TemplateNotification;
-import net.pterodactylus.util.template.Template;
-
-/**
- * Notification that signals that new Sones have been discovered.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class NewSoneNotification extends TemplateNotification {
-
-       /** The new Sones. */
-       private List<Sone> newSones = Collections.synchronizedList(new ArrayList<Sone>());
-
-       /**
-        * Creates a new “new Sone discovered” notification.
-        *
-        * @param template
-        *            The template to render
-        */
-       public NewSoneNotification(Template template) {
-               super(template);
-               template.set("sones", newSones);
-       }
-
-       //
-       // ACCESSORS
-       //
-
-       /**
-        * Returns whether there are any new Sones.
-        *
-        * @return {@code true} if there are no new Sones, {@code false} if there
-        *         are new Sones
-        */
-       public boolean isEmpty() {
-               return newSones.isEmpty();
-       }
-
-       /**
-        * Adds a discovered Sone.
-        *
-        * @param sone
-        *            The new Sone
-        */
-       public void addSone(Sone sone) {
-               newSones.add(sone);
-               touch();
-       }
-
-       /**
-        * Removes the given Sone from the list of new Sones.
-        *
-        * @param sone
-        *            The Sone to remove
-        */
-       public void removeSone(Sone sone) {
-               newSones.remove(sone);
-               touch();
-       }
-
-       //
-       // ABSTRACTNOTIFICATION METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public void dismiss() {
-               super.dismiss();
-               newSones.clear();
-       }
-
-}
index e16ca9d..db1880b 100644 (file)
@@ -37,9 +37,7 @@ import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.freenet.L10nFilter;
 import net.pterodactylus.sone.freenet.wot.Identity;
 import net.pterodactylus.sone.main.SonePlugin;
-import net.pterodactylus.sone.notify.NewPostNotification;
-import net.pterodactylus.sone.notify.NewReplyNotification;
-import net.pterodactylus.sone.notify.NewSoneNotification;
+import net.pterodactylus.sone.notify.ListNotification;
 import net.pterodactylus.sone.template.CollectionAccessor;
 import net.pterodactylus.sone.template.CssClassNameFilter;
 import net.pterodactylus.sone.template.GetPagePlugin;
@@ -113,13 +111,13 @@ public class WebInterface implements CoreListener {
        private DefaultTemplateFactory templateFactory;
 
        /** The “new Sone” notification. */
-       private final NewSoneNotification newSoneNotification;
+       private final ListNotification<Sone> newSoneNotification;
 
        /** The “new post” notification. */
-       private final NewPostNotification newPostNotification;
+       private final ListNotification<Post> newPostNotification;
 
        /** The “new reply” notification. */
-       private final NewReplyNotification newReplyNotification;
+       private final ListNotification<Reply> newReplyNotification;
 
        /**
         * Creates a new web interface.
@@ -153,13 +151,13 @@ public class WebInterface implements CoreListener {
 
                /* create notifications. */
                Template newSoneNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newSoneNotification.html"));
-               newSoneNotification = new NewSoneNotification(newSoneNotificationTemplate);
+               newSoneNotification = new ListNotification<Sone>("new-sone-notification", "sones", newSoneNotificationTemplate);
 
                Template newPostNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newPostNotification.html"));
-               newPostNotification = new NewPostNotification(newPostNotificationTemplate);
+               newPostNotification = new ListNotification<Post>("new-post-notification", "posts", newPostNotificationTemplate);
 
                Template newReplyNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newReplyNotification.html"));
-               newReplyNotification = new NewReplyNotification(newReplyNotificationTemplate);
+               newReplyNotification = new ListNotification<Reply>("new-replies-notification", "replies", newReplyNotificationTemplate);
        }
 
        //
@@ -390,7 +388,7 @@ public class WebInterface implements CoreListener {
         */
        @Override
        public void newSoneFound(Sone sone) {
-               newSoneNotification.addSone(sone);
+               newSoneNotification.add(sone);
                notificationManager.addNotification(newSoneNotification);
        }
 
@@ -399,7 +397,7 @@ public class WebInterface implements CoreListener {
         */
        @Override
        public void newPostFound(Post post) {
-               newPostNotification.addPost(post);
+               newPostNotification.add(post);
                notificationManager.addNotification(newPostNotification);
        }
 
@@ -411,7 +409,7 @@ public class WebInterface implements CoreListener {
                if (reply.getPost().getSone() == null) {
                        return;
                }
-               newReplyNotification.addReply(reply);
+               newReplyNotification.add(reply);
                notificationManager.addNotification(newReplyNotification);
        }
 
@@ -420,7 +418,7 @@ public class WebInterface implements CoreListener {
         */
        @Override
        public void markSoneKnown(Sone sone) {
-               newSoneNotification.removeSone(sone);
+               newSoneNotification.remove(sone);
                if (newSoneNotification.isEmpty()) {
                        newSoneNotification.dismiss();
                }
@@ -431,7 +429,7 @@ public class WebInterface implements CoreListener {
         */
        @Override
        public void markPostKnown(Post post) {
-               newPostNotification.removePost(post);
+               newPostNotification.remove(post);
                if (newPostNotification.isEmpty()) {
                        newPostNotification.dismiss();
                }
@@ -442,7 +440,7 @@ public class WebInterface implements CoreListener {
         */
        @Override
        public void markReplyKnown(Reply reply) {
-               newReplyNotification.removeReply(reply);
+               newReplyNotification.remove(reply);
                if (newReplyNotification.isEmpty()) {
                        newReplyNotification.dismiss();
                }