diff options
author | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-06-08 16:29:13 +0200 |
---|---|---|
committer | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-06-08 16:29:13 +0200 |
commit | 3ff911ab930cb87f90307b9a82dafc4d0b5fe305 (patch) | |
tree | 5019f591188fd57d07c16a3e03820876f2e08f48 /src/jrummikub/util | |
parent | ce1b716e128bef53b140344bf1e58960fa32cba6 (diff) | |
download | JRummikub-3ff911ab930cb87f90307b9a82dafc4d0b5fe305.tar JRummikub-3ff911ab930cb87f90307b9a82dafc4d0b5fe305.zip |
man kann speichern und laden, nur nicht während eines laufenden spiels laden
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@386 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/util')
-rw-r--r-- | src/jrummikub/util/Event3.java | 46 | ||||
-rw-r--r-- | src/jrummikub/util/IEvent3.java | 28 | ||||
-rw-r--r-- | src/jrummikub/util/IListener3.java | 22 |
3 files changed, 96 insertions, 0 deletions
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 <T1> + * type of the first event parameter + * @param <T2> + * type of the second event parameter + */ +public class Event3<T1, T2, T3> implements IEvent3<T1, T2, T3> { + private HashSet<IListener3<T1, T2, T3>> listeners = new HashSet<IListener3<T1, T2, T3>>(); + + @Override + public Connection add(final IListener3<T1, T2, T3> listener) { + listeners.add(listener); + return new Connection() { + + @Override + public void remove() { + Event3.this.remove(listener); + } + }; + } + + @Override + public void remove(IListener3<T1, T2, T3> 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<T1, T2, T3> 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 <T1> + * type of the first event parameter + * @param <T2> + * type of the second event parameter + */ +public interface IEvent3<T1, T2, T3> { + /** + * Start to publish all events to a given listener + * + * @param listener + * target listener + * @return a connection to remove the listener + */ + public Connection add(IListener3<T1, T2, T3> listener); + + /** + * Stop publishing events to a given listener + * + * @param listener + * target listener + */ + public void remove(IListener3<T1, T2, T3> 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 <T1> + * type of the first event parameter + * @param <T2> + * type of the first event parameter + */ +public interface IListener3<T1, T2, T3> { + /** + * 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); +} |