Convert “Sone removed” into EventBus-based event.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 16 Jan 2013 17:53:57 +0000 (18:53 +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/SoneRemovedEvent.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/WebInterface.java

index 0275e8a..c62a06f 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.SoneRemovedEvent;
 import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Client;
 import net.pterodactylus.sone.data.Image;
@@ -2433,7 +2434,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                synchronized (sones) {
                        sones.remove(identity.getId());
                }
-               coreListenerManager.fireSoneRemoved(sone);
+               eventBus.post(new SoneRemovedEvent(sone));
        }
 
        //
index f2ec67a..970d9e9 100644 (file)
@@ -34,14 +34,6 @@ import net.pterodactylus.util.version.Version;
 public interface CoreListener extends EventListener {
 
        /**
-        * Notifies a listener that the given Sone was removed.
-        *
-        * @param sone
-        *            The removed Sone
-        */
-       public void soneRemoved(Sone sone);
-
-       /**
         * Notifies a listener that the given post was removed.
         *
         * @param post
index a88bef5..25f24c3 100644 (file)
@@ -46,19 +46,6 @@ public class CoreListenerManager extends AbstractListenerManager<Core, CoreListe
        //
 
        /**
-        * Notifies all listener that the given Sone was removed.
-        *
-        * @see CoreListener#soneRemoved(Sone)
-        * @param sone
-        *            The removed Sone
-        */
-       void fireSoneRemoved(Sone sone) {
-               for (CoreListener coreListener : getListeners()) {
-                       coreListener.soneRemoved(sone);
-               }
-       }
-
-       /**
         * Notifies all listener that the given post was removed.
         *
         * @see CoreListener#postRemoved(Post)
diff --git a/src/main/java/net/pterodactylus/sone/core/event/SoneRemovedEvent.java b/src/main/java/net/pterodactylus/sone/core/event/SoneRemovedEvent.java
new file mode 100644 (file)
index 0000000..5b2e5d8
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Sone - SoneRemovedEvent.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.Sone;
+
+/**
+ * Event that signals that a {@link Sone} was removed.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class SoneRemovedEvent extends SoneEvent {
+
+       /**
+        * Creates a new “Sone removed” event.
+        *
+        * @param sone
+        *            The Sone that was removed
+        */
+       public SoneRemovedEvent(Sone sone) {
+               super(sone);
+       }
+
+}
index b6d2d37..14bbcc4 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.SoneRemovedEvent;
 import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Image;
 import net.pterodactylus.sone.data.Post;
@@ -887,18 +888,21 @@ public class WebInterface implements CoreListener {
                mentionNotification.remove(markPostReplyKnownEvent.postReply().getPost());
        }
 
-       //
-       // CORELISTENER METHODS
-       //
-
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that a {@link Sone} was removed.
+        *
+        * @param soneRemovedEvent
+        *            The event
         */
-       @Override
-       public void soneRemoved(Sone sone) {
-               newSoneNotification.remove(sone);
+       @Subscribe
+       public void soneRemoved(SoneRemovedEvent soneRemovedEvent) {
+               newSoneNotification.remove(soneRemovedEvent.sone());
        }
 
+       //
+       // CORELISTENER METHODS
+       //
+
        /**
         * {@inheritDoc}
         */