HHH-13831 Refresh listeners when one is replaced
This commit is contained in:
parent
2f86c4983f
commit
0a2dd4e126
|
@ -139,20 +139,22 @@ class EventListenerGroupImpl<T> implements EventListenerGroup<T> {
|
||||||
|
|
||||||
if ( listeners == null ) {
|
if ( listeners == null ) {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
listeners = (T[]) Array.newInstance( eventType.baseListenerInterface(), 1 );
|
this.listeners = (T[]) Array.newInstance( eventType.baseListenerInterface(), 1 );
|
||||||
listeners[0] = listener;
|
this.listeners[0] = listener;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final int size = listeners.length;
|
final int size = this.listeners.length;
|
||||||
|
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
final T[] newCopy = (T[]) Array.newInstance( eventType.baseListenerInterface(), size+1 );
|
final T[] newCopy = (T[]) Array.newInstance( eventType.baseListenerInterface(), size+1 );
|
||||||
|
|
||||||
// put the new one first
|
// first copy the existing listeners
|
||||||
newCopy[0] = listener;
|
System.arraycopy( this.listeners, 0, newCopy, 0, size );
|
||||||
|
|
||||||
// and copy the rest after it
|
// and then put the new one after them
|
||||||
System.arraycopy( listeners, 0, newCopy, 1, size );
|
newCopy[size] = listener;
|
||||||
|
|
||||||
|
this.listeners = newCopy;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -174,22 +176,24 @@ class EventListenerGroupImpl<T> implements EventListenerGroup<T> {
|
||||||
private void internalPrepend(T listener) {
|
private void internalPrepend(T listener) {
|
||||||
prepareListener( listener );
|
prepareListener( listener );
|
||||||
|
|
||||||
if ( listeners == null ) {
|
if ( this.listeners == null ) {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
listeners = (T[]) Array.newInstance( eventType.baseListenerInterface(), 1 );
|
this.listeners = (T[]) Array.newInstance( eventType.baseListenerInterface(), 1 );
|
||||||
listeners[0] = listener;
|
this.listeners[0] = listener;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final int size = listeners.length;
|
final int size = this.listeners.length;
|
||||||
|
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
final T[] newCopy = (T[]) Array.newInstance( eventType.baseListenerInterface(), size+1 );
|
final T[] newCopy = (T[]) Array.newInstance( eventType.baseListenerInterface(), size+1 );
|
||||||
|
|
||||||
// first copy the existing listeners
|
// put the new one first
|
||||||
System.arraycopy( listeners, 0, newCopy, 0, size );
|
newCopy[0] = listener;
|
||||||
|
|
||||||
// and then put the new one after them
|
// and copy the rest after it
|
||||||
newCopy[size] = listener;
|
System.arraycopy( this.listeners, 0, newCopy, 1, size );
|
||||||
|
|
||||||
|
this.listeners = newCopy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue