CopyOnWriteArrayList
instead, it's part of the JDK and it's more
efficientpublic final class ListenerList extends Object
Note that the add
method checks for and eliminates duplicates based on identity
(not equality). Likewise, the remove
method compares based on identity.
Use the getListeners
method when notifying listeners. Note that no garbage is
created if no listeners are registered. 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); }
Constructor and Description |
---|
ListenerList()
Deprecated.
Creates a listener list with an initial capacity of 1.
|
ListenerList(int capacity)
Deprecated.
Creates a listener list with the given initial capacity.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Object listener)
Deprecated.
Adds the given listener to this list.
|
void |
clear()
Deprecated.
Removes all listeners from this list.
|
Object[] |
getListeners()
Deprecated.
Returns an array containing all the registered listeners, in the order in which they were
added.
|
boolean |
isEmpty()
Deprecated.
Returns whether this listener list is empty.
|
void |
remove(Object listener)
Deprecated.
Removes the given listener from this list.
|
int |
size()
Deprecated.
Returns the number of registered listeners.
|
public ListenerList()
public ListenerList(int capacity)
capacity
- the number of listeners which this list can initially accept without growing
its internal representation; must be at least 1public void add(Object listener)
listener
- the listenerpublic void clear()
public Object[] getListeners()
The resulting array is unaffected by subsequent adds or removes. If there are no listeners registered, the result is an empty array singleton instance (no garbage is created). Use this method when notifying listeners, so that any modifications to the listener list during the notification will have no effect on the notification itself.
public boolean isEmpty()
true
if there are no registered listeners, and false
otherwisepublic void remove(Object listener)
listener
- the listenerpublic int size()
Copyright © 1996–2019 Geotools. All rights reserved.