Convert “post removed” into EventBus-based event.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 16 Jan 2013 17:58:27 +0000 (18:58 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 16 Jan 2013 18:04:11 +0000 (19:04 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/CoreListener.java
src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java
src/main/java/net/pterodactylus/sone/core/event/PostRemovedEvent.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/WebInterface.java

index c62a06f..81e5e09 100644 (file)
@@ -41,6 +41,7 @@ import net.pterodactylus.sone.core.event.MarkSoneKnownEvent;
 import net.pterodactylus.sone.core.event.NewPostFoundEvent;
 import net.pterodactylus.sone.core.event.NewPostReplyFoundEvent;
 import net.pterodactylus.sone.core.event.NewSoneFoundEvent;
+import net.pterodactylus.sone.core.event.PostRemovedEvent;
 import net.pterodactylus.sone.core.event.SoneRemovedEvent;
 import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Client;
@@ -1107,7 +1108,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                                        for (Post post : storedSone.getPosts()) {
                                                posts.remove(post.getId());
                                                if (!sone.getPosts().contains(post)) {
-                                                       coreListenerManager.firePostRemoved(post);
+                                                       eventBus.post(new PostRemovedEvent(post));
                                                }
                                        }
                                }
@@ -1580,7 +1581,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                synchronized (posts) {
                        posts.remove(post.getId());
                }
-               coreListenerManager.firePostRemoved(post);
+               eventBus.post(new PostRemovedEvent(post));
                markPostKnown(post);
                touchConfiguration();
        }
@@ -2419,7 +2420,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                        synchronized (knownPosts) {
                                for (Post post : sone.getPosts()) {
                                        posts.remove(post.getId());
-                                       coreListenerManager.firePostRemoved(post);
+                                       eventBus.post(new PostRemovedEvent(post));
                                }
                        }
                }
index 970d9e9..937ffb6 100644 (file)
@@ -20,7 +20,6 @@ package net.pterodactylus.sone.core;
 import java.util.EventListener;
 
 import net.pterodactylus.sone.data.Image;
-import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.util.version.Version;
@@ -34,14 +33,6 @@ import net.pterodactylus.util.version.Version;
 public interface CoreListener extends EventListener {
 
        /**
-        * Notifies a listener that the given post was removed.
-        *
-        * @param post
-        *            The removed post
-        */
-       public void postRemoved(Post post);
-
-       /**
         * Notifies a listener that the given reply was removed.
         *
         * @param reply
index 25f24c3..a0c6d22 100644 (file)
@@ -18,7 +18,6 @@
 package net.pterodactylus.sone.core;
 
 import net.pterodactylus.sone.data.Image;
-import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.util.event.AbstractListenerManager;
@@ -46,19 +45,6 @@ public class CoreListenerManager extends AbstractListenerManager<Core, CoreListe
        //
 
        /**
-        * Notifies all listener that the given post was removed.
-        *
-        * @see CoreListener#postRemoved(Post)
-        * @param post
-        *            The removed post
-        */
-       void firePostRemoved(Post post) {
-               for (CoreListener coreListener : getListeners()) {
-                       coreListener.postRemoved(post);
-               }
-       }
-
-       /**
         * Notifies all listener that the given reply was removed.
         *
         * @see CoreListener#replyRemoved(PostReply)
diff --git a/src/main/java/net/pterodactylus/sone/core/event/PostRemovedEvent.java b/src/main/java/net/pterodactylus/sone/core/event/PostRemovedEvent.java
new file mode 100644 (file)
index 0000000..7e07df7
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Sone - PostRemovedEvent.java - Copyright © 2013 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.core.event;
+
+import net.pterodactylus.sone.data.Post;
+
+/**
+ * Event that signals that a {@link Post} was removed.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class PostRemovedEvent extends PostEvent {
+
+       /**
+        * Creates a new “post removed” event.
+        *
+        * @param post
+        *            The post that was removed
+        */
+       public PostRemovedEvent(Post post) {
+               super(post);
+       }
+
+}
index 14bbcc4..53f7dd9 100644 (file)
@@ -43,6 +43,7 @@ import net.pterodactylus.sone.core.event.MarkSoneKnownEvent;
 import net.pterodactylus.sone.core.event.NewPostFoundEvent;
 import net.pterodactylus.sone.core.event.NewPostReplyFoundEvent;
 import net.pterodactylus.sone.core.event.NewSoneFoundEvent;
+import net.pterodactylus.sone.core.event.PostRemovedEvent;
 import net.pterodactylus.sone.core.event.SoneRemovedEvent;
 import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Image;
@@ -899,20 +900,23 @@ public class WebInterface implements CoreListener {
                newSoneNotification.remove(soneRemovedEvent.sone());
        }
 
-       //
-       // CORELISTENER METHODS
-       //
-
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that a {@link Post} was removed.
+        *
+        * @param postRemovedEvent
+        *            The event
         */
-       @Override
-       public void postRemoved(Post post) {
-               newPostNotification.remove(post);
-               localPostNotification.remove(post);
-               mentionNotification.remove(post);
+       @Subscribe
+       public void postRemoved(PostRemovedEvent postRemovedEvent) {
+               newPostNotification.remove(postRemovedEvent.post());
+               localPostNotification.remove(postRemovedEvent.post());
+               mentionNotification.remove(postRemovedEvent.post());
        }
 
+       //
+       // CORELISTENER METHODS
+       //
+
        /**
         * {@inheritDoc}
         */