public class PriorityListenerList<T extends EventListener> extends Object implements Serializable
Constructor and Description |
---|
PriorityListenerList() |
Modifier and Type | Method and Description |
---|---|
void |
add(T listener,
int priority)
Add listener with the given priority.
|
int |
getListenerCount()
Get total count of listeners contained in this list at all priority levels.
|
T[][] |
getListenersArray()
Return the actual array of listeners arrays maintained by this listeners list.
|
void |
remove(T listener,
int priority)
Remove listener with the given priority index.
|
public void add(T listener, int priority)
listener
- listener to be added. If null is passed it is ignored (nothing gets added).priority
- >=0 index defining priority
with which the listener should be fired.
IndexOutOfBoundsException
- when priority < 0public void remove(T listener, int priority)
listener
- listener to be removed. If null is passed it is ignored (nothing gets removed).priority
- >=0 index defining priority
with which the listener was originally added.
IndexOutOfBoundsException
- when priority < 0public T[][] getListenersArray()
The higher index means sooner firing. Listeners with the same priority are ordered so that the one added sooner has higher index than the one added later. So the following firing mechanism should be used:
private void fireMyEvent(MyEvent evt) { MyListener[][] listenersArray = priorityListenerList.getListenersArray(); for (int priority = listenersArray.length - 1; priority >= 0; priority--) { MyListener[] listeners = listenersArray[priority]; for (int i = listeners.length - 1; i >= 0; i--) { listeners[i].notify(evt); } } }
public int getListenerCount()