Convert “new post 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 reply has been found.
50          *
51          * @see CoreListener#newReplyFound(PostReply)
52          * @param reply
53          *            The new reply
54          */
55         void fireNewReplyFound(PostReply reply) {
56                 for (CoreListener coreListener : getListeners()) {
57                         coreListener.newReplyFound(reply);
58                 }
59         }
60
61         /**
62          * Notifies all listeners that the given Sone is now marked as known.
63          *
64          * @see CoreListener#markSoneKnown(Sone)
65          * @param sone
66          *            The known Sone
67          */
68         void fireMarkSoneKnown(Sone sone) {
69                 for (CoreListener coreListener : getListeners()) {
70                         coreListener.markSoneKnown(sone);
71                 }
72         }
73
74         /**
75          * Notifies all listeners that the given post is now marked as known.
76          *
77          * @param post
78          *            The known post
79          */
80         void fireMarkPostKnown(Post post) {
81                 for (CoreListener coreListener : getListeners()) {
82                         coreListener.markPostKnown(post);
83                 }
84         }
85
86         /**
87          * Notifies all listeners that the given reply is now marked as known.
88          *
89          * @param reply
90          *            The known reply
91          */
92         void fireMarkReplyKnown(PostReply reply) {
93                 for (CoreListener coreListener : getListeners()) {
94                         coreListener.markReplyKnown(reply);
95                 }
96         }
97
98         /**
99          * Notifies all listener that the given Sone was removed.
100          *
101          * @see CoreListener#soneRemoved(Sone)
102          * @param sone
103          *            The removed Sone
104          */
105         void fireSoneRemoved(Sone sone) {
106                 for (CoreListener coreListener : getListeners()) {
107                         coreListener.soneRemoved(sone);
108                 }
109         }
110
111         /**
112          * Notifies all listener that the given post was removed.
113          *
114          * @see CoreListener#postRemoved(Post)
115          * @param post
116          *            The removed post
117          */
118         void firePostRemoved(Post post) {
119                 for (CoreListener coreListener : getListeners()) {
120                         coreListener.postRemoved(post);
121                 }
122         }
123
124         /**
125          * Notifies all listener that the given reply was removed.
126          *
127          * @see CoreListener#replyRemoved(PostReply)
128          * @param reply
129          *            The removed reply
130          */
131         void fireReplyRemoved(PostReply reply) {
132                 for (CoreListener coreListener : getListeners()) {
133                         coreListener.replyRemoved(reply);
134                 }
135         }
136
137         /**
138          * Notifies all listeners that the given Sone was locked.
139          *
140          * @see CoreListener#soneLocked(Sone)
141          * @param sone
142          *            The Sone that was locked
143          */
144         void fireSoneLocked(Sone sone) {
145                 for (CoreListener coreListener : getListeners()) {
146                         coreListener.soneLocked(sone);
147                 }
148         }
149
150         /**
151          * Notifies all listeners that the given Sone was unlocked.
152          *
153          * @see CoreListener#soneUnlocked(Sone)
154          * @param sone
155          *            The Sone that was unlocked
156          */
157         void fireSoneUnlocked(Sone sone) {
158                 for (CoreListener coreListener : getListeners()) {
159                         coreListener.soneUnlocked(sone);
160                 }
161         }
162
163         /**
164          * Notifies all listeners that the insert of the given Sone has started.
165          *
166          * @see SoneInsertListener#insertStarted(Sone)
167          * @param sone
168          *            The Sone being inserted
169          */
170         void fireSoneInserting(Sone sone) {
171                 for (CoreListener coreListener : getListeners()) {
172                         coreListener.soneInserting(sone);
173                 }
174         }
175
176         /**
177          * Notifies all listeners that the insert of the given Sone has finished
178          * successfully.
179          *
180          * @see SoneInsertListener#insertFinished(Sone, long)
181          * @param sone
182          *            The Sone that was inserted
183          * @param insertDuration
184          *            The insert duration (in milliseconds)
185          */
186         void fireSoneInserted(Sone sone, long insertDuration) {
187                 for (CoreListener coreListener : getListeners()) {
188                         coreListener.soneInserted(sone, insertDuration);
189                 }
190         }
191
192         /**
193          * Notifies all listeners that the insert of the given Sone was aborted.
194          *
195          * @see SoneInsertListener#insertStarted(Sone)
196          * @param sone
197          *            The Sone being inserted
198          * @param cause
199          *            The cause for the abortion (may be {@code null}
200          */
201         void fireSoneInsertAborted(Sone sone, Throwable cause) {
202                 for (CoreListener coreListener : getListeners()) {
203                         coreListener.soneInsertAborted(sone, cause);
204                 }
205         }
206
207         /**
208          * Notifies all listeners that a new version was found.
209          *
210          * @see CoreListener#updateFound(Version, long, long)
211          * @param version
212          *            The new version
213          * @param releaseTime
214          *            The release time of the new version
215          * @param latestEdition
216          *            The latest edition of the Sone homepage
217          */
218         void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
219                 for (CoreListener coreListener : getListeners()) {
220                         coreListener.updateFound(version, releaseTime, latestEdition);
221                 }
222         }
223
224         /**
225          * Notifies all listeners that an image has started being inserted.
226          *
227          * @see CoreListener#imageInsertStarted(Image)
228          * @param image
229          *            The image that is now inserted
230          */
231         void fireImageInsertStarted(Image image) {
232                 for (CoreListener coreListener : getListeners()) {
233                         coreListener.imageInsertStarted(image);
234                 }
235         }
236
237         /**
238          * Notifies all listeners that an image insert was aborted by the user.
239          *
240          * @see CoreListener#imageInsertAborted(Image)
241          * @param image
242          *            The image that is not inserted anymore
243          */
244         void fireImageInsertAborted(Image image) {
245                 for (CoreListener coreListener : getListeners()) {
246                         coreListener.imageInsertAborted(image);
247                 }
248         }
249
250         /**
251          * Notifies all listeners that an image was successfully inserted.
252          *
253          * @see CoreListener#imageInsertFinished(Image)
254          * @param image
255          *            The image that was inserted
256          */
257         void fireImageInsertFinished(Image image) {
258                 for (CoreListener coreListener : getListeners()) {
259                         coreListener.imageInsertFinished(image);
260                 }
261         }
262
263         /**
264          * Notifies all listeners that an image failed to be inserted.
265          *
266          * @see CoreListener#imageInsertFailed(Image, Throwable)
267          * @param image
268          *            The image that could not be inserted
269          * @param cause
270          *            The cause of the failure
271          */
272         void fireImageInsertFailed(Image image, Throwable cause) {
273                 for (CoreListener coreListener : getListeners()) {
274                         coreListener.imageInsertFailed(image, cause);
275                 }
276         }
277
278 }