v0.4.3b: improvements to the signal class
This commit is contained in:
parent
10e1a17704
commit
6ee0a30db8
|
@ -39,7 +39,7 @@ public class Signal<T> {
|
||||||
this.stackMode = stackMode;
|
this.stackMode = stackMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add( Listener<T> listener ) {
|
public synchronized void add( Listener<T> listener ) {
|
||||||
if (!listeners.contains( listener )) {
|
if (!listeners.contains( listener )) {
|
||||||
if (stackMode) {
|
if (stackMode) {
|
||||||
listeners.addFirst( listener );
|
listeners.addFirst( listener );
|
||||||
|
@ -49,33 +49,28 @@ public class Signal<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove( Listener<T> listener ) {
|
public synchronized void remove( Listener<T> listener ) {
|
||||||
listeners.remove( listener );
|
listeners.remove( listener );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAll() {
|
public synchronized void removeAll() {
|
||||||
listeners.clear();
|
listeners.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replace( Listener<T> listener ) {
|
public synchronized void replace( Listener<T> listener ) {
|
||||||
removeAll();
|
removeAll();
|
||||||
add( listener );
|
add( listener );
|
||||||
}
|
}
|
||||||
|
|
||||||
public int numListeners() {
|
public synchronized int numListeners() {
|
||||||
return listeners.size();
|
return listeners.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispatch( T t ) {
|
public synchronized void dispatch( T t ) {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Listener<T>[] list = listeners.toArray( new Listener[0] );
|
|
||||||
|
|
||||||
canceled = false;
|
canceled = false;
|
||||||
for (int i=0; i < list.length; i++) {
|
for (Listener<T> listener : listeners) {
|
||||||
|
|
||||||
Listener<T> listener = list[i];
|
|
||||||
|
|
||||||
if (listeners.contains( listener )) {
|
if (listeners.contains( listener )) {
|
||||||
listener.onSignal( t );
|
listener.onSignal( t );
|
||||||
if (canceled) {
|
if (canceled) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user