public class ListenerList
extends java.lang.Object
A listener list handles the same listener being added multiple times, and tolerates removal of listeners that are the same as other listeners in the list. For this purpose, listeners can be compared with each other using either equality or identity, as specified in the list constructor.
Use the getListeners() method when notifying listeners. The recommended
code sequence for notifying all registered listeners of say,
FooListener.eventHappened, is:
Object[] listeners = myListenerList.getListeners();
for (int i = 0; i < listeners.length; ++i) {
((FooListener) listeners[i]).eventHappened(event);
}
This class can be used without OSGi running.
| Modifier and Type | Field and Description |
|---|---|
static int |
EQUALITY
Mode constant (value 0) indicating that listeners should be considered
the same if they are equal.
|
static int |
IDENTITY
Mode constant (value 1) indicating that listeners should be considered
the same if they are identical.
|
| Constructor and Description |
|---|
ListenerList()
Creates a listener list in which listeners are compared using equality.
|
ListenerList(int mode)
Creates a listener list using the provided comparison mode.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(java.lang.Object listener)
Adds a listener to this list.
|
void |
clear()
Removes all listeners from this list.
|
java.lang.Object[] |
getListeners()
Returns an array containing all the registered listeners.
|
boolean |
isEmpty()
Returns whether this listener list is empty.
|
void |
remove(java.lang.Object listener)
Removes a listener from this list.
|
int |
size()
Returns the number of registered listeners.
|
public static final int EQUALITY
public static final int IDENTITY
public ListenerList()
public ListenerList(int mode)
mode - The mode used to determine if listeners are the same.public void add(java.lang.Object listener)
listener - the non-null listener to addpublic void clear()
public java.lang.Object[] getListeners()
Note: Callers of this method must not modify the returned array.
public boolean isEmpty()
true if there are no registered listeners, and
false otherwisepublic void remove(java.lang.Object listener)
listener - the non-null listener to removepublic int size()
© Copyright 2014 Etherios, Inc. All rights reserved. Etherios, Inc. is a Division of Digi International Inc.