summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Clayton <alex.clayton@isode.com>2016-01-18 12:30:15 (GMT)
committerAlex Clayton <alex.clayton@isode.com>2016-01-18 15:45:59 (GMT)
commitfa1633e3b4d75a8217459cdc5fe64e9ee5ace65a (patch)
treeb07c9ba91604541db47620f599bced17fdeccc48 /src/com/isode/stroke/base
parent72249383639858b1a7947b1afc6b9491ebd82bf8 (diff)
downloadstroke-fa1633e3b4d75a8217459cdc5fe64e9ee5ace65a.zip
stroke-fa1633e3b4d75a8217459cdc5fe64e9ee5ace65a.tar.bz2
Some Jingle Fixes
Some fixes to the Jingle classes for the previous patch. Test-information: By code inspection. Ran Unit Tests there were no failures. Change-Id: I61210dd1ec2c7e0dd11d67a45a0ced63952804c7
Diffstat (limited to 'src/com/isode/stroke/base')
-rwxr-xr-xsrc/com/isode/stroke/base/Listenable.java58
1 files changed, 28 insertions, 30 deletions
diff --git a/src/com/isode/stroke/base/Listenable.java b/src/com/isode/stroke/base/Listenable.java
index c0aa091..1f7eed1 100755
--- a/src/com/isode/stroke/base/Listenable.java
+++ b/src/com/isode/stroke/base/Listenable.java
@@ -11,15 +11,12 @@
package com.isode.stroke.base;
-import java.util.Vector;
-import com.isode.stroke.signals.Slot;
-import com.isode.stroke.signals.Slot1;
-import com.isode.stroke.signals.Slot2;
-import com.isode.stroke.signals.Slot3;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
public class Listenable<T> {
- private Vector<T> listeners = new Vector<T>();
+ private Set<T> listeners = new CopyOnWriteArraySet<T>();
public void addListener(T listener) {
listeners.add(listener);
@@ -30,30 +27,31 @@ public class Listenable<T> {
listeners.remove(listener);
}
}
-
- //Swiften code calls event(i), which is not yet done.
- public void notifyListeners(Slot event) {
- for (T i : listeners) {
- event.call();
- }
- }
-
- //Swiften code calls event(i), which is not yet done.
- public <T1> void notifyListeners(Slot1<T1> event, T1 p1) {
- for (T i : listeners) {
- event.call(p1);
- }
+
+ // Swiften code takes advantage of boost binding
+ // which we can't do in java. Easiest solution seems
+ // to be to pass listener to the caller to handle which
+ // method should be called
+ public void notifyListeners(ListenableCallback<? super T> callback) {
+ for (T listener : listeners) {
+ callback.call(listener);
+ }
}
-
- public <T1, T2> void notifyListeners(Slot2<T1, T2> event, T1 p1, T2 p2) {
- for (T i : listeners) {
- event.call(p1, p2);
- }
- }
-
- public <T1, T2, T3> void notifyListeners(Slot3<T1, T2, T3> event, T1 p1, T2 p2, T3 p3) {
- for (T i : listeners) {
- event.call(p1, p2, p3);
- }
+
+ /**
+ * Callback for subclasses to specify how the listers should be
+ * called
+ * @param <T> Type of listener that can registered with the {@link Listenable}
+ */
+ public static interface ListenableCallback<S> {
+
+ /**
+ * Called by the parent {@link Listenable} class for all
+ * registered listeners.
+ * @param listener A registered listener. May be {@code null}
+ * if a {@code null} was registered as a listener.
+ */
+ public void call(S listener);
+
}
} \ No newline at end of file