public class ListenerList extends Object
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(Object listener)
Adds a listener to this list.
|
void |
clear()
Removes all listeners from this list.
|
Object[] |
getListeners()
Returns an array containing all the registered listeners.
|
boolean |
isEmpty()
Returns whether this listener list is empty.
|
void |
remove(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(Object listener)
listener
- the non-null
listener to addpublic 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(Object listener)
listener
- the non-null
listener to removepublic int size()
public void clear()
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.