Convert update events to EventBus-based events.
[Sone.git] / src / main / java / net / pterodactylus / sone / freenet / wot / IdentityListenerManager.java
1 /*
2  * Sone - IdentityListenerManager.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.freenet.wot;
19
20 import net.pterodactylus.util.event.AbstractListenerManager;
21
22 /**
23  * Manager for {@link IdentityListener}s.
24  *
25  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
26  */
27 public class IdentityListenerManager extends AbstractListenerManager<IdentityManager, IdentityListener> {
28
29         /**
30          * Creates a new identity listener manager.
31          */
32         public IdentityListenerManager() {
33                 super(null);
34         }
35
36         //
37         // ACTIONS
38         //
39
40         /**
41          * Notifies all listeners that an {@link OwnIdentity} that was not known on
42          * the previous check is available.
43          *
44          * @see IdentityListener#ownIdentityAdded(OwnIdentity)
45          * @param ownIdentity
46          *            The new own identity
47          */
48         public void fireOwnIdentityAdded(OwnIdentity ownIdentity) {
49                 for (IdentityListener identityListener : getListeners()) {
50                         identityListener.ownIdentityAdded(ownIdentity);
51                 }
52         }
53
54         /**
55          * Notifies all listeners that an {@link OwnIdentity} that was available
56          * during the last check has gone away.
57          *
58          * @see IdentityListener#ownIdentityRemoved(OwnIdentity)
59          * @param ownIdentity
60          *            The disappeared own identity
61          */
62         public void fireOwnIdentityRemoved(OwnIdentity ownIdentity) {
63                 for (IdentityListener identityListener : getListeners()) {
64                         identityListener.ownIdentityRemoved(ownIdentity);
65                 }
66         }
67
68         /**
69          * Notifies all listeners that a new identity was discovered.
70          *
71          * @see IdentityListener#identityAdded(OwnIdentity, Identity)
72          * @param ownIdentity
73          *            The own identity at the root of the trust tree
74          * @param identity
75          *            The new identity
76          */
77         public void fireIdentityAdded(OwnIdentity ownIdentity, Identity identity) {
78                 for (IdentityListener identityListener : getListeners()) {
79                         identityListener.identityAdded(ownIdentity, identity);
80                 }
81         }
82
83         /**
84          * Notifies all listeners that some properties of the identity have changed.
85          *
86          * @see IdentityListener#identityUpdated(OwnIdentity, Identity)
87          * @param ownIdentity
88          *            The own identity at the root of the trust tree
89          * @param identity
90          *            The updated identity
91          */
92         public void fireIdentityUpdated(OwnIdentity ownIdentity, Identity identity) {
93                 for (IdentityListener identityListener : getListeners()) {
94                         identityListener.identityUpdated(ownIdentity, identity);
95                 }
96         }
97
98         /**
99          * Notifies all listeners that an identity has gone away.
100          *
101          * @see IdentityListener#identityRemoved(OwnIdentity, Identity)
102          * @param ownIdentity
103          *            The own identity at the root of the trust tree
104          * @param identity
105          *            The disappeared identity
106          */
107         public void fireIdentityRemoved(OwnIdentity ownIdentity, Identity identity) {
108                 for (IdentityListener identityListener : getListeners()) {
109                         identityListener.identityRemoved(ownIdentity, identity);
110                 }
111         }
112
113 }