From 3ff911ab930cb87f90307b9a82dafc4d0b5fe305 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Wed, 8 Jun 2011 16:29:13 +0200 Subject: =?UTF-8?q?man=20kann=20speichern=20und=20laden,=20nur=20nicht=20w?= =?UTF-8?q?=C3=A4hrend=20eines=20laufenden=20spiels=20laden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@386 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/util/Event3.java | 46 ++++++++++++++++++++++++++++++++++++++ src/jrummikub/util/IEvent3.java | 28 +++++++++++++++++++++++ src/jrummikub/util/IListener3.java | 22 ++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 src/jrummikub/util/Event3.java create mode 100644 src/jrummikub/util/IEvent3.java create mode 100644 src/jrummikub/util/IListener3.java (limited to 'src/jrummikub/util') diff --git a/src/jrummikub/util/Event3.java b/src/jrummikub/util/Event3.java new file mode 100644 index 0000000..a309111 --- /dev/null +++ b/src/jrummikub/util/Event3.java @@ -0,0 +1,46 @@ +package jrummikub.util; + +import java.util.HashSet; + +/** + * Simple single parameter event generator + * + * @param + * type of the first event parameter + * @param + * type of the second event parameter + */ +public class Event3 implements IEvent3 { + private HashSet> listeners = new HashSet>(); + + @Override + public Connection add(final IListener3 listener) { + listeners.add(listener); + return new Connection() { + + @Override + public void remove() { + Event3.this.remove(listener); + } + }; + } + + @Override + public void remove(IListener3 listener) { + listeners.remove(listener); + } + + /** + * Generate a single event + * + * @param value1 + * the first event parameter + * @param value2 + * the second event parameter + */ + public void emit(T1 value1, T2 value2, T3 value3) { + for (IListener3 listener : listeners) { + listener.handle(value1, value2, value3); + } + } +} diff --git a/src/jrummikub/util/IEvent3.java b/src/jrummikub/util/IEvent3.java new file mode 100644 index 0000000..fd04364 --- /dev/null +++ b/src/jrummikub/util/IEvent3.java @@ -0,0 +1,28 @@ +package jrummikub.util; + +/** + * Interface for classes that can generate events having a two parameters + * + * @param + * type of the first event parameter + * @param + * type of the second event parameter + */ +public interface IEvent3 { + /** + * Start to publish all events to a given listener + * + * @param listener + * target listener + * @return a connection to remove the listener + */ + public Connection add(IListener3 listener); + + /** + * Stop publishing events to a given listener + * + * @param listener + * target listener + */ + public void remove(IListener3 listener); +} diff --git a/src/jrummikub/util/IListener3.java b/src/jrummikub/util/IListener3.java new file mode 100644 index 0000000..ae1d6ce --- /dev/null +++ b/src/jrummikub/util/IListener3.java @@ -0,0 +1,22 @@ +package jrummikub.util; + +/** + * Interface for classes that can receive parameterless events having a two + * parameters + * + * @param + * type of the first event parameter + * @param + * type of the first event parameter + */ +public interface IListener3 { + /** + * This method is called whenever a class we're listening to emits an event + * + * @param value1 + * the first event parameter + * @param value2 + * the second event parameter + */ + public void handle(T1 value1, T2 value2, T3 value3); +} -- cgit v1.2.3