From: David ‘Bombe’ Roden Date: Thu, 17 Jan 2013 05:59:16 +0000 (+0100) Subject: Convert identity events into EventBus-based events. X-Git-Tag: 0.8.5^2~3^2~87 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=8c1a4ad1d3f11ba0a11a077c47df48425360e0ac;p=Sone.git Convert identity events into EventBus-based events. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index bd1bf37..82fb4c5 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -63,9 +63,13 @@ import net.pterodactylus.sone.data.impl.PostImpl; import net.pterodactylus.sone.fcp.FcpInterface; import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired; import net.pterodactylus.sone.freenet.wot.Identity; -import net.pterodactylus.sone.freenet.wot.IdentityListener; import net.pterodactylus.sone.freenet.wot.IdentityManager; import net.pterodactylus.sone.freenet.wot.OwnIdentity; +import net.pterodactylus.sone.freenet.wot.event.IdentityAddedEvent; +import net.pterodactylus.sone.freenet.wot.event.IdentityRemovedEvent; +import net.pterodactylus.sone.freenet.wot.event.IdentityUpdatedEvent; +import net.pterodactylus.sone.freenet.wot.event.OwnIdentityAddedEvent; +import net.pterodactylus.sone.freenet.wot.event.OwnIdentityRemovedEvent; import net.pterodactylus.sone.main.SonePlugin; import net.pterodactylus.util.config.Configuration; import net.pterodactylus.util.config.ConfigurationException; @@ -92,7 +96,7 @@ import freenet.keys.FreenetURI; * * @author David ‘Bombe’ Roden */ -public class Core extends AbstractService implements IdentityListener, SoneProvider, PostProvider { +public class Core extends AbstractService implements SoneProvider, PostProvider { /** The logger. */ private static final Logger logger = Logging.getLogger(Core.class); @@ -1885,7 +1889,6 @@ public class Core extends AbstractService implements IdentityListener, SoneProvi public void serviceStart() { loadConfiguration(); updateChecker.start(); - identityManager.addIdentityListener(this); identityManager.start(); webOfTrustUpdater.init(); webOfTrustUpdater.start(); @@ -1925,7 +1928,6 @@ public class Core extends AbstractService implements IdentityListener, SoneProvi webOfTrustUpdater.stop(); updateChecker.stop(); soneDownloader.stop(); - identityManager.removeIdentityListener(this); identityManager.stop(); } @@ -2310,15 +2312,15 @@ public class Core extends AbstractService implements IdentityListener, SoneProvi } } - // - // INTERFACE IdentityListener - // - /** - * {@inheritDoc} + * Notifies the core that a new {@link OwnIdentity} was added. + * + * @param ownIdentityAddedEvent + * The event */ - @Override - public void ownIdentityAdded(OwnIdentity ownIdentity) { + @Subscribe + public void ownIdentityAdded(OwnIdentityAddedEvent ownIdentityAddedEvent) { + OwnIdentity ownIdentity = ownIdentityAddedEvent.ownIdentity(); logger.log(Level.FINEST, String.format("Adding OwnIdentity: %s", ownIdentity)); if (ownIdentity.hasContext("Sone")) { trustedIdentities.put(ownIdentity, Collections.synchronizedSet(new HashSet())); @@ -2327,29 +2329,41 @@ public class Core extends AbstractService implements IdentityListener, SoneProvi } /** - * {@inheritDoc} + * Notifies the core that an {@link OwnIdentity} was removed. + * + * @param ownIdentityRemovedEvent + * The event */ - @Override - public void ownIdentityRemoved(OwnIdentity ownIdentity) { + @Subscribe + public void ownIdentityRemoved(OwnIdentityRemovedEvent ownIdentityRemovedEvent) { + OwnIdentity ownIdentity = ownIdentityRemovedEvent.ownIdentity(); logger.log(Level.FINEST, String.format("Removing OwnIdentity: %s", ownIdentity)); trustedIdentities.remove(ownIdentity); } /** - * {@inheritDoc} + * Notifies the core that a new {@link Identity} was added. + * + * @param identityAddedEvent + * The event */ - @Override - public void identityAdded(OwnIdentity ownIdentity, Identity identity) { + @Subscribe + public void identityAdded(IdentityAddedEvent identityAddedEvent) { + Identity identity = identityAddedEvent.identity(); logger.log(Level.FINEST, String.format("Adding Identity: %s", identity)); - trustedIdentities.get(ownIdentity).add(identity); + trustedIdentities.get(identityAddedEvent.ownIdentity()).add(identity); addRemoteSone(identity); } /** - * {@inheritDoc} + * Notifies the core that an {@link Identity} was updated. + * + * @param identityUpdatedEvent + * The event */ - @Override - public void identityUpdated(OwnIdentity ownIdentity, final Identity identity) { + @Subscribe + public void identityUpdated(IdentityUpdatedEvent identityUpdatedEvent) { + final Identity identity = identityUpdatedEvent.identity(); soneDownloaders.execute(new Runnable() { @Override @@ -2365,10 +2379,15 @@ public class Core extends AbstractService implements IdentityListener, SoneProvi } /** - * {@inheritDoc} + * Notifies the core that an {@link Identity} was removed. + * + * @param identityRemovedEvent + * The event */ - @Override - public void identityRemoved(OwnIdentity ownIdentity, Identity identity) { + @Subscribe + public void identityRemoved(IdentityRemovedEvent identityRemovedEvent) { + OwnIdentity ownIdentity = identityRemovedEvent.ownIdentity(); + Identity identity = identityRemovedEvent.identity(); trustedIdentities.get(ownIdentity).remove(identity); boolean foundIdentity = false; for (Entry> trustedIdentity : trustedIdentities.entrySet()) { diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityListener.java b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityListener.java deleted file mode 100644 index 51e1437..0000000 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityListener.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Sone - IdentityListener.java - Copyright © 2010–2012 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 . - */ - -package net.pterodactylus.sone.freenet.wot; - -import java.util.EventListener; - -/** - * Listener interface for {@link IdentityManager} events. - * - * @author David ‘Bombe’ Roden - */ -public interface IdentityListener extends EventListener { - - /** - * Notifies a listener that an {@link OwnIdentity} that was not known on the - * previous check is available. - * - * @param ownIdentity - * The new own identity - */ - public void ownIdentityAdded(OwnIdentity ownIdentity); - - /** - * Notifies a listener that an {@link OwnIdentity} that was available during - * the last check has gone away. - * - * @param ownIdentity - * The disappeared own identity - */ - public void ownIdentityRemoved(OwnIdentity ownIdentity); - - /** - * Notifies a listener that a new identity was discovered. - * - * @param ownIdentity - * The own identity at the root of the trust tree - * @param identity - * The new identity - */ - public void identityAdded(OwnIdentity ownIdentity, Identity identity); - - /** - * Notifies a listener that some properties of the identity have changed. - * - * @param ownIdentity - * The own identity at the root of the trust tree - * @param identity - * The updated identity - */ - public void identityUpdated(OwnIdentity ownIdentity, Identity identity); - - /** - * Notifies a listener that an identity has gone away. - * - * @param ownIdentity - * The own identity at the root of the trust tree - * @param identity - * The disappeared identity - */ - public void identityRemoved(OwnIdentity ownIdentity, Identity identity); - -} diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityListenerManager.java b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityListenerManager.java deleted file mode 100644 index 50808a2..0000000 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityListenerManager.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Sone - IdentityListenerManager.java - Copyright © 2010–2012 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 . - */ - -package net.pterodactylus.sone.freenet.wot; - -import net.pterodactylus.util.event.AbstractListenerManager; - -/** - * Manager for {@link IdentityListener}s. - * - * @author David ‘Bombe’ Roden - */ -public class IdentityListenerManager extends AbstractListenerManager { - - /** - * Creates a new identity listener manager. - */ - public IdentityListenerManager() { - super(null); - } - - // - // ACTIONS - // - - /** - * Notifies all listeners that an {@link OwnIdentity} that was not known on - * the previous check is available. - * - * @see IdentityListener#ownIdentityAdded(OwnIdentity) - * @param ownIdentity - * The new own identity - */ - public void fireOwnIdentityAdded(OwnIdentity ownIdentity) { - for (IdentityListener identityListener : getListeners()) { - identityListener.ownIdentityAdded(ownIdentity); - } - } - - /** - * Notifies all listeners that an {@link OwnIdentity} that was available - * during the last check has gone away. - * - * @see IdentityListener#ownIdentityRemoved(OwnIdentity) - * @param ownIdentity - * The disappeared own identity - */ - public void fireOwnIdentityRemoved(OwnIdentity ownIdentity) { - for (IdentityListener identityListener : getListeners()) { - identityListener.ownIdentityRemoved(ownIdentity); - } - } - - /** - * Notifies all listeners that a new identity was discovered. - * - * @see IdentityListener#identityAdded(OwnIdentity, Identity) - * @param ownIdentity - * The own identity at the root of the trust tree - * @param identity - * The new identity - */ - public void fireIdentityAdded(OwnIdentity ownIdentity, Identity identity) { - for (IdentityListener identityListener : getListeners()) { - identityListener.identityAdded(ownIdentity, identity); - } - } - - /** - * Notifies all listeners that some properties of the identity have changed. - * - * @see IdentityListener#identityUpdated(OwnIdentity, Identity) - * @param ownIdentity - * The own identity at the root of the trust tree - * @param identity - * The updated identity - */ - public void fireIdentityUpdated(OwnIdentity ownIdentity, Identity identity) { - for (IdentityListener identityListener : getListeners()) { - identityListener.identityUpdated(ownIdentity, identity); - } - } - - /** - * Notifies all listeners that an identity has gone away. - * - * @see IdentityListener#identityRemoved(OwnIdentity, Identity) - * @param ownIdentity - * The own identity at the root of the trust tree - * @param identity - * The disappeared identity - */ - public void fireIdentityRemoved(OwnIdentity ownIdentity, Identity identity) { - for (IdentityListener identityListener : getListeners()) { - identityListener.identityRemoved(ownIdentity, identity); - } - } - -} diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java index 5b86db4..fc77b2d 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java @@ -27,9 +27,15 @@ import java.util.logging.Level; import java.util.logging.Logger; import net.pterodactylus.sone.freenet.plugin.PluginException; +import net.pterodactylus.sone.freenet.wot.event.IdentityAddedEvent; +import net.pterodactylus.sone.freenet.wot.event.IdentityRemovedEvent; +import net.pterodactylus.sone.freenet.wot.event.IdentityUpdatedEvent; +import net.pterodactylus.sone.freenet.wot.event.OwnIdentityAddedEvent; +import net.pterodactylus.sone.freenet.wot.event.OwnIdentityRemovedEvent; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.service.AbstractService; +import com.google.common.eventbus.EventBus; import com.google.inject.Inject; import com.google.inject.name.Named; @@ -39,7 +45,7 @@ import com.google.inject.name.Named; * exceptions but it only logs them and tries to return sensible defaults. *

* It is also responsible for polling identities from the Web of Trust plugin - * and notifying registered {@link IdentityListener}s when {@link Identity}s and + * and sending events to the {@link EventBus} when {@link Identity}s and * {@link OwnIdentity}s are discovered or disappearing. * * @author David ‘Bombe’ Roden @@ -55,8 +61,8 @@ public class IdentityManager extends AbstractService { /** The logger. */ private static final Logger logger = Logging.getLogger(IdentityManager.class); - /** The event manager. */ - private final IdentityListenerManager identityListenerManager = new IdentityListenerManager(); + /** The event bus. */ + private final EventBus eventBus; /** The Web of Trust connector. */ private final WebOfTrustConnector webOfTrustConnector; @@ -74,6 +80,8 @@ public class IdentityManager extends AbstractService { /** * Creates a new identity manager. * + * @param eventBus + * The event bus * @param webOfTrustConnector * The Web of Trust connector * @param context @@ -81,37 +89,14 @@ public class IdentityManager extends AbstractService { * contexts) */ @Inject - public IdentityManager(WebOfTrustConnector webOfTrustConnector, @Named("WebOfTrustContext") String context) { + public IdentityManager(EventBus eventBus, WebOfTrustConnector webOfTrustConnector, @Named("WebOfTrustContext") String context) { super("Sone Identity Manager", false); + this.eventBus = eventBus; this.webOfTrustConnector = webOfTrustConnector; this.context = context; } // - // LISTENER MANAGEMENT - // - - /** - * Adds a listener for identity events. - * - * @param identityListener - * The listener to add - */ - public void addIdentityListener(IdentityListener identityListener) { - identityListenerManager.addListener(identityListener); - } - - /** - * Removes a listener for identity events. - * - * @param identityListener - * The listener to remove - */ - public void removeIdentityListener(IdentityListener identityListener) { - identityListenerManager.removeListener(identityListener); - } - - // // ACCESSORS // @@ -225,7 +210,7 @@ public class IdentityManager extends AbstractService { /* find new identities. */ for (Identity currentIdentity : currentIdentities.get(ownIdentity).values()) { if (!oldIdentities.containsKey(ownIdentity) || !oldIdentities.get(ownIdentity).containsKey(currentIdentity.getId())) { - identityListenerManager.fireIdentityAdded(ownIdentity, currentIdentity); + eventBus.post(new IdentityAddedEvent(ownIdentity, currentIdentity)); } } @@ -233,7 +218,7 @@ public class IdentityManager extends AbstractService { if (oldIdentities.containsKey(ownIdentity)) { for (Identity oldIdentity : oldIdentities.get(ownIdentity).values()) { if (!currentIdentities.get(ownIdentity).containsKey(oldIdentity.getId())) { - identityListenerManager.fireIdentityRemoved(ownIdentity, oldIdentity); + eventBus.post(new IdentityRemovedEvent(ownIdentity, oldIdentity)); } } @@ -246,12 +231,12 @@ public class IdentityManager extends AbstractService { Set oldContexts = oldIdentity.getContexts(); Set newContexts = newIdentity.getContexts(); if (oldContexts.size() != newContexts.size()) { - identityListenerManager.fireIdentityUpdated(ownIdentity, newIdentity); + eventBus.post(new IdentityUpdatedEvent(ownIdentity, newIdentity)); continue; } for (String oldContext : oldContexts) { if (!newContexts.contains(oldContext)) { - identityListenerManager.fireIdentityUpdated(ownIdentity, newIdentity); + eventBus.post(new IdentityUpdatedEvent(ownIdentity, newIdentity)); break; } } @@ -266,12 +251,12 @@ public class IdentityManager extends AbstractService { Map oldProperties = oldIdentity.getProperties(); Map newProperties = newIdentity.getProperties(); if (oldProperties.size() != newProperties.size()) { - identityListenerManager.fireIdentityUpdated(ownIdentity, newIdentity); + eventBus.post(new IdentityUpdatedEvent(ownIdentity, newIdentity)); continue; } for (Entry oldProperty : oldProperties.entrySet()) { if (!newProperties.containsKey(oldProperty.getKey()) || !newProperties.get(oldProperty.getKey()).equals(oldProperty.getValue())) { - identityListenerManager.fireIdentityUpdated(ownIdentity, newIdentity); + eventBus.post(new IdentityUpdatedEvent(ownIdentity, newIdentity)); break; } } @@ -306,7 +291,7 @@ public class IdentityManager extends AbstractService { for (OwnIdentity oldOwnIdentity : currentOwnIdentities.values()) { OwnIdentity newOwnIdentity = newOwnIdentities.get(oldOwnIdentity.getId()); if ((newOwnIdentity == null) || ((context != null) && oldOwnIdentity.hasContext(context) && !newOwnIdentity.hasContext(context))) { - identityListenerManager.fireOwnIdentityRemoved(new DefaultOwnIdentity(oldOwnIdentity)); + eventBus.post(new OwnIdentityRemovedEvent(new DefaultOwnIdentity(oldOwnIdentity))); } } @@ -314,7 +299,7 @@ public class IdentityManager extends AbstractService { for (OwnIdentity currentOwnIdentity : newOwnIdentities.values()) { OwnIdentity oldOwnIdentity = currentOwnIdentities.get(currentOwnIdentity.getId()); if (((oldOwnIdentity == null) && ((context == null) || currentOwnIdentity.hasContext(context))) || ((oldOwnIdentity != null) && (context != null) && (!oldOwnIdentity.hasContext(context) && currentOwnIdentity.hasContext(context)))) { - identityListenerManager.fireOwnIdentityAdded(new DefaultOwnIdentity(currentOwnIdentity)); + eventBus.post(new OwnIdentityAddedEvent(new DefaultOwnIdentity(currentOwnIdentity))); } } diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/event/IdentityAddedEvent.java b/src/main/java/net/pterodactylus/sone/freenet/wot/event/IdentityAddedEvent.java new file mode 100644 index 0000000..69f17ef --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/event/IdentityAddedEvent.java @@ -0,0 +1,42 @@ +/* + * Sone - IdentityAddedEvent.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 . + */ + +package net.pterodactylus.sone.freenet.wot.event; + +import net.pterodactylus.sone.freenet.wot.Identity; +import net.pterodactylus.sone.freenet.wot.OwnIdentity; + +/** + * Event that signals that an {@link Identity} was added. + * + * @author David ‘Bombe’ Roden + */ +public class IdentityAddedEvent extends IdentityEvent { + + /** + * Creates a new “identity added” event. + * + * @param ownIdentity + * The own identity that added the identity + * @param identity + * The identity that was added + */ + public IdentityAddedEvent(OwnIdentity ownIdentity, Identity identity) { + super(ownIdentity, identity); + } + +} diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/event/IdentityEvent.java b/src/main/java/net/pterodactylus/sone/freenet/wot/event/IdentityEvent.java new file mode 100644 index 0000000..2727226 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/event/IdentityEvent.java @@ -0,0 +1,71 @@ +/* + * Sone - IdentityEvent.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 . + */ + +package net.pterodactylus.sone.freenet.wot.event; + +import net.pterodactylus.sone.freenet.wot.Identity; +import net.pterodactylus.sone.freenet.wot.OwnIdentity; + +/** + * Base class for {@link Identity} events. + * + * @author David ‘Bombe’ Roden + */ +public abstract class IdentityEvent { + + /** The own identity this event relates to. */ + private final OwnIdentity ownIdentity; + + /** The identity this event is about. */ + private final Identity identity; + + /** + * Creates a new identity-based event. + * + * @param ownIdentity + * The own identity that relates to the identity + * @param identity + * The identity this event is about + */ + protected IdentityEvent(OwnIdentity ownIdentity, Identity identity) { + this.ownIdentity = ownIdentity; + this.identity = identity; + } + + // + // ACCESSORS + // + + /** + * Returns the own identity this event relates to. + * + * @return The own identity this event relates to + */ + public OwnIdentity ownIdentity() { + return ownIdentity; + } + + /** + * Returns the identity this event is about. + * + * @return The identity this event is about + */ + public Identity identity() { + return identity; + } + +} diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/event/IdentityRemovedEvent.java b/src/main/java/net/pterodactylus/sone/freenet/wot/event/IdentityRemovedEvent.java new file mode 100644 index 0000000..d5671cc --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/event/IdentityRemovedEvent.java @@ -0,0 +1,42 @@ +/* + * Sone - IdentityRemovedEvent.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 . + */ + +package net.pterodactylus.sone.freenet.wot.event; + +import net.pterodactylus.sone.freenet.wot.Identity; +import net.pterodactylus.sone.freenet.wot.OwnIdentity; + +/** + * Event that signals that an {@link Identity} was removed. + * + * @author David ‘Bombe’ Roden + */ +public class IdentityRemovedEvent extends IdentityEvent { + + /** + * Creates a new “identity removed” event. + * + * @param ownIdentity + * The own identity that removed the identity + * @param identity + * The identity that was removed + */ + public IdentityRemovedEvent(OwnIdentity ownIdentity, Identity identity) { + super(ownIdentity, identity); + } + +} diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/event/IdentityUpdatedEvent.java b/src/main/java/net/pterodactylus/sone/freenet/wot/event/IdentityUpdatedEvent.java new file mode 100644 index 0000000..96ed694 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/event/IdentityUpdatedEvent.java @@ -0,0 +1,42 @@ +/* + * Sone - IdentityUpdatedEvent.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 . + */ + +package net.pterodactylus.sone.freenet.wot.event; + +import net.pterodactylus.sone.freenet.wot.Identity; +import net.pterodactylus.sone.freenet.wot.OwnIdentity; + +/** + * Event that signals that an {@link Identity} was updated. + * + * @author David ‘Bombe’ Roden + */ +public class IdentityUpdatedEvent extends IdentityEvent { + + /** + * Creates a new “identity updated” event. + * + * @param ownIdentity + * The own identity that tracks the identity + * @param identity + * The identity that was updated + */ + public IdentityUpdatedEvent(OwnIdentity ownIdentity, Identity identity) { + super(ownIdentity, identity); + } + +} diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/event/OwnIdentityAddedEvent.java b/src/main/java/net/pterodactylus/sone/freenet/wot/event/OwnIdentityAddedEvent.java new file mode 100644 index 0000000..aacf2e8 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/event/OwnIdentityAddedEvent.java @@ -0,0 +1,39 @@ +/* + * Sone - OwnIdentityAddedEvent.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 . + */ + +package net.pterodactylus.sone.freenet.wot.event; + +import net.pterodactylus.sone.freenet.wot.OwnIdentity; + +/** + * Event that signals that an {@link OwnIdentity} was added. + * + * @author David ‘Bombe’ Roden + */ +public class OwnIdentityAddedEvent extends OwnIdentityEvent { + + /** + * Creates new “own identity added” event. + * + * @param ownIdentity + * The own identity that was added + */ + public OwnIdentityAddedEvent(OwnIdentity ownIdentity) { + super(ownIdentity); + } + +} diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/event/OwnIdentityEvent.java b/src/main/java/net/pterodactylus/sone/freenet/wot/event/OwnIdentityEvent.java new file mode 100644 index 0000000..97179e8 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/event/OwnIdentityEvent.java @@ -0,0 +1,55 @@ +/* + * Sone - OwnIdentityEvent.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 . + */ + +package net.pterodactylus.sone.freenet.wot.event; + +import net.pterodactylus.sone.freenet.wot.OwnIdentity; + +/** + * Base class for {@link OwnIdentity} events. + * + * @author David ‘Bombe’ Roden + */ +public abstract class OwnIdentityEvent { + + /** The own identity this event is about. */ + private final OwnIdentity ownIdentity; + + /** + * Creates a new own identity-based event. + * + * @param ownIdentity + * The own identity this event is about + */ + protected OwnIdentityEvent(OwnIdentity ownIdentity) { + this.ownIdentity = ownIdentity; + } + + // + // ACCESSORS + // + + /** + * Returns the own identity this event is about. + * + * @return The own identity this event is about + */ + public OwnIdentity ownIdentity() { + return ownIdentity; + } + +} diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/event/OwnIdentityRemovedEvent.java b/src/main/java/net/pterodactylus/sone/freenet/wot/event/OwnIdentityRemovedEvent.java new file mode 100644 index 0000000..437bd6d --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/event/OwnIdentityRemovedEvent.java @@ -0,0 +1,39 @@ +/* + * Sone - OwnIdentityRemovedEvent.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 . + */ + +package net.pterodactylus.sone.freenet.wot.event; + +import net.pterodactylus.sone.freenet.wot.OwnIdentity; + +/** + * Event that signals that an {@link OwnIdentity} was removed. + * + * @author David ‘Bombe’ Roden + */ +public class OwnIdentityRemovedEvent extends OwnIdentityEvent { + + /** + * Creates a new “own identity removed” event. + * + * @param ownIdentity + * The own identity that was removed + */ + public OwnIdentityRemovedEvent(OwnIdentity ownIdentity) { + super(ownIdentity); + } + +}