diff options
Diffstat (limited to 'src/jrummikub/util')
-rw-r--r-- | src/jrummikub/util/Event.java | 23 | ||||
-rw-r--r-- | src/jrummikub/util/Event1.java | 23 | ||||
-rw-r--r-- | src/jrummikub/util/IEvent.java | 6 | ||||
-rw-r--r-- | src/jrummikub/util/IEvent1.java | 6 | ||||
-rw-r--r-- | src/jrummikub/util/IListener.java | 5 | ||||
-rw-r--r-- | src/jrummikub/util/IListener1.java | 5 |
6 files changed, 68 insertions, 0 deletions
diff --git a/src/jrummikub/util/Event.java b/src/jrummikub/util/Event.java new file mode 100644 index 0000000..0b2317f --- /dev/null +++ b/src/jrummikub/util/Event.java @@ -0,0 +1,23 @@ +package jrummikub.util; + +import java.util.HashSet; + +public class Event implements IEvent { + private HashSet<IListener> listeners = new HashSet<IListener>(); + + @Override + public void add(IListener listener) { + listeners.add(listener); + } + + @Override + public void remove(IListener listener) { + listeners.remove(listener); + } + + public void fire() { + for (IListener listener : listeners) { + listener.fire(); + } + } +} diff --git a/src/jrummikub/util/Event1.java b/src/jrummikub/util/Event1.java new file mode 100644 index 0000000..e8ccb43 --- /dev/null +++ b/src/jrummikub/util/Event1.java @@ -0,0 +1,23 @@ +package jrummikub.util; + +import java.util.HashSet; + +public class Event1<T> implements IEvent1<T> { + private HashSet<IListener1<T>> listeners = new HashSet<IListener1<T>>(); + + @Override + public void add(IListener1<T> listener) { + listeners.add(listener); + } + + @Override + public void remove(IListener1<T> listener) { + listeners.remove(listener); + } + + public void fire(T value) { + for (IListener1<T> listener : listeners) { + listener.fire(value); + } + } +} diff --git a/src/jrummikub/util/IEvent.java b/src/jrummikub/util/IEvent.java new file mode 100644 index 0000000..ce0e13d --- /dev/null +++ b/src/jrummikub/util/IEvent.java @@ -0,0 +1,6 @@ +package jrummikub.util; + +public interface IEvent { + public void add(IListener listener); + public void remove(IListener listener); +} diff --git a/src/jrummikub/util/IEvent1.java b/src/jrummikub/util/IEvent1.java new file mode 100644 index 0000000..47075db --- /dev/null +++ b/src/jrummikub/util/IEvent1.java @@ -0,0 +1,6 @@ +package jrummikub.util; + +public interface IEvent1<T> { + public void add(IListener1<T> listener); + public void remove(IListener1<T> listener); +} diff --git a/src/jrummikub/util/IListener.java b/src/jrummikub/util/IListener.java new file mode 100644 index 0000000..37d79c0 --- /dev/null +++ b/src/jrummikub/util/IListener.java @@ -0,0 +1,5 @@ +package jrummikub.util; + +public interface IListener { + public void fire(); +} diff --git a/src/jrummikub/util/IListener1.java b/src/jrummikub/util/IListener1.java new file mode 100644 index 0000000..8dfeaf3 --- /dev/null +++ b/src/jrummikub/util/IListener1.java @@ -0,0 +1,5 @@ +package jrummikub.util; + +public interface IListener1<T> { + public void fire(T value); +} |