Convert “new Sound found” into EventBus-based event.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / CoreListenerManager.java
1 /*
2  * Sone - CoreListenerManager.java - Copyright © 2010–2012 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.sone.core;
19
20 import net.pterodactylus.sone.data.Image;
21 import net.pterodactylus.sone.data.Post;
22 import net.pterodactylus.sone.data.PostReply;
23 import net.pterodactylus.sone.data.Sone;
24 import net.pterodactylus.util.event.AbstractListenerManager;
25 import net.pterodactylus.util.version.Version;
26
27 /**
28  * Manager for {@link CoreListener}s.
29  *
30  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
31  */
32 public class CoreListenerManager extends AbstractListenerManager<Core, CoreListener> {
33
34         /**
35          * Creates a new core listener manager.
36          *
37          * @param source
38          *            The Core
39          */
40         public CoreListenerManager(Core source) {
41                 super(source);
42         }
43
44         //
45         // ACTIONS
46         //
47
48         /**
49          * Notifies all listeners that a new post has been found.
50          *
51          * @see CoreListener#newPostFound(Post)
52          * @param post
53          *            The new post
54          */
55         void fireNewPostFound(Post post) {
56                 for (CoreListener coreListener : getListeners()) {
57                         coreListener.newPostFound(post);
58                 }
59         }
60
61         /**
62          * Notifies all listeners that a new reply has been found.
63          *
64          * @see CoreListener#newReplyFound(PostReply)
65          * @param reply
66          *            The new reply
67          */
68         void fireNewReplyFound(PostReply reply) {
69                 for (CoreListener coreListener : getListeners()) {
70                         coreListener.newReplyFound(reply);
71                 }
72         }
73
74         /**
75          * Notifies all listeners that the given Sone is now marked as known.
76          *
77          * @see CoreListener#markSoneKnown(Sone)
78          * @param sone
79          *            The known Sone
80          */
81         void fireMarkSoneKnown(Sone sone) {
82                 for (CoreListener coreListener : getListeners()) {
83                         coreListener.markSoneKnown(sone);
84                 }
85         }
86
87         /**
88          * Notifies all listeners that the given post is now marked as known.
89          *
90          * @param post
91          *            The known post
92          */
93         void fireMarkPostKnown(Post post) {
94                 for (CoreListener coreListener : getListeners()) {
95                         coreListener.markPostKnown(post);
96                 }
97         }
98
99         /**
100          * Notifies all listeners that the given reply is now marked as known.
101          *
102          * @param reply
103          *            The known reply
104          */
105         void fireMarkReplyKnown(PostReply reply) {
106                 for (CoreListener coreListener : getListeners()) {
107                         coreListener.markReplyKnown(reply);
108                 }
109         }
110
111         /**
112          * Notifies all listener that the given Sone was removed.
113          *
114          * @see CoreListener#soneRemoved(Sone)
115          * @param sone
116          *            The removed Sone
117          */
118         void fireSoneRemoved(Sone sone) {
119                 for (CoreListener coreListener : getListeners()) {
120                         coreListener.soneRemoved(sone);
121                 }
122         }
123
124         /**
125          * Notifies all listener that the given post was removed.
126          *
127          * @see CoreListener#postRemoved(Post)
128          * @param post
129          *            The removed post
130          */
131         void firePostRemoved(Post post) {
132                 for (CoreListener coreListener : getListeners()) {
133                         coreListener.postRemoved(post);
134                 }
135         }
136
137         /**
138          * Notifies all listener that the given reply was removed.
139          *
140          * @see CoreListener#replyRemoved(PostReply)
141          * @param reply
142          *            The removed reply
143          */
144         void fireReplyRemoved(PostReply reply) {
145                 for (CoreListener coreListener : getListeners()) {
146                         coreListener.replyRemoved(reply);
147                 }
148         }
149
150         /**
151          * Notifies all listeners that the given Sone was locked.
152          *
153          * @see CoreListener#soneLocked(Sone)
154          * @param sone
155          *            The Sone that was locked
156          */
157         void fireSoneLocked(Sone sone) {
158                 for (CoreListener coreListener : getListeners()) {
159                         coreListener.soneLocked(sone);
160                 }
161         }
162
163         /**
164          * Notifies all listeners that the given Sone was unlocked.
165          *
166          * @see CoreListener#soneUnlocked(Sone)
167          * @param sone
168          *            The Sone that was unlocked
169          */
170         void fireSoneUnlocked(Sone sone) {
171                 for (CoreListener coreListener : getListeners()) {
172                         coreListener.soneUnlocked(sone);
173                 }
174         }
175
176         /**
177          * Notifies all listeners that the insert of the given Sone has started.
178          *
179          * @see SoneInsertListener#insertStarted(Sone)
180          * @param sone
181          *            The Sone being inserted
182          */
183         void fireSoneInserting(Sone sone) {
184                 for (CoreListener coreListener : getListeners()) {
185                         coreListener.soneInserting(sone);
186                 }
187         }
188
189         /**
190          * Notifies all listeners that the insert of the given Sone has finished
191          * successfully.
192          *
193          * @see SoneInsertListener#insertFinished(Sone, long)
194          * @param sone
195          *            The Sone that was inserted
196          * @param insertDuration
197          *            The insert duration (in milliseconds)
198          */
199         void fireSoneInserted(Sone sone, long insertDuration) {
200                 for (CoreListener coreListener : getListeners()) {
201                         coreListener.soneInserted(sone, insertDuration);
202                 }
203         }
204
205         /**
206          * Notifies all listeners that the insert of the given Sone was aborted.
207          *
208          * @see SoneInsertListener#insertStarted(Sone)
209          * @param sone
210          *            The Sone being inserted
211          * @param cause
212          *            The cause for the abortion (may be {@code null}
213          */
214         void fireSoneInsertAborted(Sone sone, Throwable cause) {
215                 for (CoreListener coreListener : getListeners()) {
216                         coreListener.soneInsertAborted(sone, cause);
217                 }
218         }
219
220         /**
221          * Notifies all listeners that a new version was found.
222          *
223          * @see CoreListener#updateFound(Version, long, long)
224          * @param version
225          *            The new version
226          * @param releaseTime
227          *            The release time of the new version
228          * @param latestEdition
229          *            The latest edition of the Sone homepage
230          */
231         void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
232                 for (CoreListener coreListener : getListeners()) {
233                         coreListener.updateFound(version, releaseTime, latestEdition);
234                 }
235         }
236
237         /**
238          * Notifies all listeners that an image has started being inserted.
239          *
240          * @see CoreListener#imageInsertStarted(Image)
241          * @param image
242          *            The image that is now inserted
243          */
244         void fireImageInsertStarted(Image image) {
245                 for (CoreListener coreListener : getListeners()) {
246                         coreListener.imageInsertStarted(image);
247                 }
248         }
249
250         /**
251          * Notifies all listeners that an image insert was aborted by the user.
252          *
253          * @see CoreListener#imageInsertAborted(Image)
254          * @param image
255          *            The image that is not inserted anymore
256          */
257         void fireImageInsertAborted(Image image) {
258                 for (CoreListener coreListener : getListeners()) {
259                         coreListener.imageInsertAborted(image);
260                 }
261         }
262
263         /**
264          * Notifies all listeners that an image was successfully inserted.
265          *
266          * @see CoreListener#imageInsertFinished(Image)
267          * @param image
268          *            The image that was inserted
269          */
270         void fireImageInsertFinished(Image image) {
271                 for (CoreListener coreListener : getListeners()) {
272                         coreListener.imageInsertFinished(image);
273                 }
274         }
275
276         /**
277          * Notifies all listeners that an image failed to be inserted.
278          *
279          * @see CoreListener#imageInsertFailed(Image, Throwable)
280          * @param image
281          *            The image that could not be inserted
282          * @param cause
283          *            The cause of the failure
284          */
285         void fireImageInsertFailed(Image image, Throwable cause) {
286                 for (CoreListener coreListener : getListeners()) {
287                         coreListener.imageInsertFailed(image, cause);
288                 }
289         }
290
291 }