Add Sone insert events to core listener manager.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / CoreListenerManager.java
1 /*
2  * Sone - CoreListenerManager.java - Copyright © 2010 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.Post;
21 import net.pterodactylus.sone.data.Reply;
22 import net.pterodactylus.sone.data.Sone;
23 import net.pterodactylus.util.event.AbstractListenerManager;
24 import net.pterodactylus.util.version.Version;
25
26 /**
27  * Manager for {@link CoreListener}s.
28  *
29  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
30  */
31 public class CoreListenerManager extends AbstractListenerManager<Core, CoreListener> {
32
33         /**
34          * Creates a new core listener manager.
35          *
36          * @param source
37          *            The Core
38          */
39         public CoreListenerManager(Core source) {
40                 super(source);
41         }
42
43         //
44         // ACTIONS
45         //
46
47         /**
48          * Notifies all listeners that the given Sone is now being rescued.
49          *
50          * @see CoreListener#rescuingSone(Sone)
51          * @param sone
52          *            The Sone that is being rescued
53          */
54         void fireRescuingSone(Sone sone) {
55                 for (CoreListener coreListener : getListeners()) {
56                         coreListener.rescuingSone(sone);
57                 }
58         }
59
60         /**
61          * Notifies all listeners that the given Sone was rescued.
62          *
63          * @see CoreListener#rescuedSone(Sone)
64          * @param sone
65          *            The Sone that was rescued
66          */
67         void fireRescuedSone(Sone sone) {
68                 for (CoreListener coreListener : getListeners()) {
69                         coreListener.rescuedSone(sone);
70                 }
71         }
72
73         /**
74          * Notifies all listeners that a new Sone has been discovered.
75          *
76          * @see CoreListener#newSoneFound(Sone)
77          * @param sone
78          *            The discovered sone
79          */
80         void fireNewSoneFound(Sone sone) {
81                 for (CoreListener coreListener : getListeners()) {
82                         coreListener.newSoneFound(sone);
83                 }
84         }
85
86         /**
87          * Notifies all listeners that a new post has been found.
88          *
89          * @see CoreListener#newPostFound(Post)
90          * @param post
91          *            The new post
92          */
93         void fireNewPostFound(Post post) {
94                 for (CoreListener coreListener : getListeners()) {
95                         coreListener.newPostFound(post);
96                 }
97         }
98
99         /**
100          * Notifies all listeners that a new reply has been found.
101          *
102          * @see CoreListener#newReplyFound(Reply)
103          * @param reply
104          *            The new reply
105          */
106         void fireNewReplyFound(Reply reply) {
107                 for (CoreListener coreListener : getListeners()) {
108                         coreListener.newReplyFound(reply);
109                 }
110         }
111
112         /**
113          * Notifies all listeners that the given Sone is now marked as known.
114          *
115          * @see CoreListener#markSoneKnown(Sone)
116          * @param sone
117          *            The known Sone
118          */
119         void fireMarkSoneKnown(Sone sone) {
120                 for (CoreListener coreListener : getListeners()) {
121                         coreListener.markSoneKnown(sone);
122                 }
123         }
124
125         /**
126          * Notifies all listeners that the given post is now marked as known.
127          *
128          * @param post
129          *            The known post
130          */
131         void fireMarkPostKnown(Post post) {
132                 for (CoreListener coreListener : getListeners()) {
133                         coreListener.markPostKnown(post);
134                 }
135         }
136
137         /**
138          * Notifies all listeners that the given reply is now marked as known.
139          *
140          * @param reply
141          *            The known reply
142          */
143         void fireMarkReplyKnown(Reply reply) {
144                 for (CoreListener coreListener : getListeners()) {
145                         coreListener.markReplyKnown(reply);
146                 }
147         }
148
149         /**
150          * Notifies all listener that the given Sone was removed.
151          *
152          * @see CoreListener#soneRemoved(Sone)
153          * @param sone
154          *            The removed Sone
155          */
156         void fireSoneRemoved(Sone sone) {
157                 for (CoreListener coreListener : getListeners()) {
158                         coreListener.soneRemoved(sone);
159                 }
160         }
161
162         /**
163          * Notifies all listener that the given post was removed.
164          *
165          * @see CoreListener#postRemoved(Post)
166          * @param post
167          *            The removed post
168          */
169         void firePostRemoved(Post post) {
170                 for (CoreListener coreListener : getListeners()) {
171                         coreListener.postRemoved(post);
172                 }
173         }
174
175         /**
176          * Notifies all listener that the given reply was removed.
177          *
178          * @see CoreListener#replyRemoved(Reply)
179          * @param reply
180          *            The removed reply
181          */
182         void fireReplyRemoved(Reply reply) {
183                 for (CoreListener coreListener : getListeners()) {
184                         coreListener.replyRemoved(reply);
185                 }
186         }
187
188         /**
189          * Notifies all listeners that the given Sone was locked.
190          *
191          * @see CoreListener#soneLocked(Sone)
192          * @param sone
193          *            The Sone that was locked
194          */
195         void fireSoneLocked(Sone sone) {
196                 for (CoreListener coreListener : getListeners()) {
197                         coreListener.soneLocked(sone);
198                 }
199         }
200
201         /**
202          * Notifies all listeners that the given Sone was unlocked.
203          *
204          * @see CoreListener#soneUnlocked(Sone)
205          * @param sone
206          *            The Sone that was unlocked
207          */
208         void fireSoneUnlocked(Sone sone) {
209                 for (CoreListener coreListener : getListeners()) {
210                         coreListener.soneUnlocked(sone);
211                 }
212         }
213
214         /**
215          * Notifies all listeners that the insert of the given Sone has started.
216          *
217          * @see SoneInsertListener#insertStarted(Sone)
218          * @param sone
219          *            The Sone being inserted
220          */
221         void fireSoneInserting(Sone sone) {
222                 for (CoreListener coreListener : getListeners()) {
223                         coreListener.soneInserting(sone);
224                 }
225         }
226
227         /**
228          * Notifies all listeners that the insert of the given Sone has finished
229          * successfully.
230          *
231          * @see SoneInsertListener#insertFinished(Sone, long)
232          * @param sone
233          *            The Sone that was inserted
234          * @param insertDuration
235          *            The insert duration (in milliseconds)
236          */
237         void fireSoneInserted(Sone sone, long insertDuration) {
238                 for (CoreListener coreListener : getListeners()) {
239                         coreListener.soneInserted(sone, insertDuration);
240                 }
241         }
242
243         /**
244          * Notifies all listeners that the insert of the given Sone was aborted.
245          *
246          * @see SoneInsertListener#insertStarted(Sone)
247          * @param sone
248          *            The Sone being inserted
249          * @param cause
250          *            The cause for the abortion (may be {@code null}
251          */
252         void fireSoneInsertAborted(Sone sone, Throwable cause) {
253                 for (CoreListener coreListener : getListeners()) {
254                         coreListener.soneInsertAborted(sone, cause);
255                 }
256         }
257
258         /**
259          * Notifies all listeners that a new version was found.
260          *
261          * @see CoreListener#updateFound(Version, long, long)
262          * @param version
263          *            The new version
264          * @param releaseTime
265          *            The release time of the new version
266          * @param latestEdition
267          *            The latest edition of the Sone homepage
268          */
269         void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
270                 for (CoreListener coreListener : getListeners()) {
271                         coreListener.updateFound(version, releaseTime, latestEdition);
272                 }
273         }
274
275 }