summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jrummikub/util/Connection.java6
-rw-r--r--src/jrummikub/util/Event.java44
-rw-r--r--src/jrummikub/util/Event1.java10
-rw-r--r--src/jrummikub/util/Event2.java14
-rw-r--r--src/jrummikub/util/IEvent.java1
-rw-r--r--src/jrummikub/util/IEvent1.java1
-rw-r--r--src/jrummikub/util/IEvent2.java9
7 files changed, 47 insertions, 38 deletions
diff --git a/src/jrummikub/util/Connection.java b/src/jrummikub/util/Connection.java
index b6a5a07..a14e747 100644
--- a/src/jrummikub/util/Connection.java
+++ b/src/jrummikub/util/Connection.java
@@ -1,5 +1,11 @@
package jrummikub.util;
+/**
+ * A Connection object can be used to remove a listener from a event
+ */
public interface Connection {
+ /**
+ * Removes the listener
+ */
public void remove();
}
diff --git a/src/jrummikub/util/Event.java b/src/jrummikub/util/Event.java
index 491e10f..aa491da 100644
--- a/src/jrummikub/util/Event.java
+++ b/src/jrummikub/util/Event.java
@@ -4,29 +4,29 @@ import java.util.HashSet;
/** Simple parameterless event generator */
public class Event implements IEvent {
- private HashSet<IListener> listeners = new HashSet<IListener>();
+ private HashSet<IListener> listeners = new HashSet<IListener>();
- @Override
- public Connection add(final IListener listener) {
- listeners.add(listener);
- return new Connection() {
-
- @Override
- public void remove() {
- Event.this.remove(listener);
- }
- };
- }
+ @Override
+ public Connection add(final IListener listener) {
+ listeners.add(listener);
+ return new Connection() {
+
+ @Override
+ public void remove() {
+ Event.this.remove(listener);
+ }
+ };
+ }
- @Override
- public void remove(IListener listener) {
- listeners.remove(listener);
- }
+ @Override
+ public void remove(IListener listener) {
+ listeners.remove(listener);
+ }
- /** Generate a single event */
- public void emit() {
- for (IListener listener : listeners) {
- listener.handle();
- }
- }
+ /** Generate a single event */
+ public void emit() {
+ for (IListener listener : listeners) {
+ listener.handle();
+ }
+ }
}
diff --git a/src/jrummikub/util/Event1.java b/src/jrummikub/util/Event1.java
index d721a7e..5e3391c 100644
--- a/src/jrummikub/util/Event1.java
+++ b/src/jrummikub/util/Event1.java
@@ -6,7 +6,7 @@ import java.util.HashSet;
* Simple single parameter event generator
*
* @param <T>
- * type of the event parameter
+ * type of the event parameter
*/
public class Event1<T> implements IEvent1<T> {
private HashSet<IListener1<T>> listeners = new HashSet<IListener1<T>>();
@@ -14,8 +14,8 @@ public class Event1<T> implements IEvent1<T> {
@Override
public Connection add(final IListener1<T> listener) {
listeners.add(listener);
- return new Connection() {
-
+ return new Connection() {
+
@Override
public void remove() {
Event1.this.remove(listener);
@@ -32,9 +32,9 @@ public class Event1<T> implements IEvent1<T> {
* Generate a single event
*
* @param value
- * the event parameter
+ * the event parameter
*/
- public void emit(T value) {
+ public void emit(T value) {
for (IListener1<T> listener : listeners) {
listener.handle(value);
}
diff --git a/src/jrummikub/util/Event2.java b/src/jrummikub/util/Event2.java
index 7087975..9bcee43 100644
--- a/src/jrummikub/util/Event2.java
+++ b/src/jrummikub/util/Event2.java
@@ -6,9 +6,9 @@ import java.util.HashSet;
* Simple single parameter event generator
*
* @param <T1>
- * type of the first event parameter
+ * type of the first event parameter
* @param <T2>
- * type of the second event parameter
+ * type of the second event parameter
*/
public class Event2<T1, T2> implements IEvent2<T1, T2> {
private HashSet<IListener2<T1, T2>> listeners = new HashSet<IListener2<T1, T2>>();
@@ -16,8 +16,8 @@ public class Event2<T1, T2> implements IEvent2<T1, T2> {
@Override
public Connection add(final IListener2<T1, T2> listener) {
listeners.add(listener);
- return new Connection() {
-
+ return new Connection() {
+
@Override
public void remove() {
Event2.this.remove(listener);
@@ -34,11 +34,11 @@ public class Event2<T1, T2> implements IEvent2<T1, T2> {
* Generate a single event
*
* @param value1
- * the first event parameter
+ * the first event parameter
* @param value2
- * the second event parameter
+ * the second event parameter
*/
- public void emit(T1 value1, T2 value2) {
+ public void emit(T1 value1, T2 value2) {
for (IListener2<T1, T2> listener : listeners) {
listener.handle(value1, value2);
}
diff --git a/src/jrummikub/util/IEvent.java b/src/jrummikub/util/IEvent.java
index 52893f2..b8d418c 100644
--- a/src/jrummikub/util/IEvent.java
+++ b/src/jrummikub/util/IEvent.java
@@ -7,6 +7,7 @@ public interface IEvent {
*
* @param listener
* target listener
+ * @return a connection to remove the listener
*/
public Connection add(IListener listener);
diff --git a/src/jrummikub/util/IEvent1.java b/src/jrummikub/util/IEvent1.java
index fa031b8..9508d05 100644
--- a/src/jrummikub/util/IEvent1.java
+++ b/src/jrummikub/util/IEvent1.java
@@ -12,6 +12,7 @@ public interface IEvent1<T> {
*
* @param listener
* target listener
+ * @return a connection to remove the listener
*/
public Connection add(IListener1<T> listener);
diff --git a/src/jrummikub/util/IEvent2.java b/src/jrummikub/util/IEvent2.java
index 70bb3e6..8958cfa 100644
--- a/src/jrummikub/util/IEvent2.java
+++ b/src/jrummikub/util/IEvent2.java
@@ -4,16 +4,17 @@ package jrummikub.util;
* Interface for classes that can generate events having a two parameters
*
* @param <T1>
- * type of the first event parameter
+ * type of the first event parameter
* @param <T2>
- * type of the second event parameter
+ * type of the second event parameter
*/
public interface IEvent2<T1, T2> {
/**
* Start to publish all events to a given listener
*
* @param listener
- * target listener
+ * target listener
+ * @return a connection to remove the listener
*/
public Connection add(IListener2<T1, T2> listener);
@@ -21,7 +22,7 @@ public interface IEvent2<T1, T2> {
* Stop publishing events to a given listener
*
* @param listener
- * target listener
+ * target listener
*/
public void remove(IListener2<T1, T2> listener);
}