Package org.geotools.data.util
Class ListenerList
- Object
- 
- ListenerList
 
- 
 public class ListenerList extends Object This class is used to maintain a list of listeners, and is used in the implementations of several classes within JFace which allow you to register listeners of various kinds. It is a fairly lightweight object, occupying minimal space when no listeners are registered.Note that the addmethod checks for and eliminates duplicates based on identity (not equality). Likewise, theremovemethod compares based on identity.Use the getListenersmethod 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 SummaryConstructors Constructor Description ListenerList()Creates a listener list with an initial capacity of 1.ListenerList(int capacity)Creates a listener list with the given initial capacity.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Object listener)Adds the given listener to this list.voidclear()Removes all listeners from this list.Object[]getListeners()Returns an array containing all the registered listeners, in the order in which they were added.booleanisEmpty()Returns whether this listener list is empty.voidremove(Object listener)Removes the given listener from this list.intsize()Returns the number of registered listeners.
 
- 
- 
- 
Constructor Detail- 
ListenerListpublic ListenerList() Creates a listener list with an initial capacity of 1.
 - 
ListenerListpublic ListenerList(int capacity) Creates a listener list with the given initial capacity.- Parameters:
- capacity- the number of listeners which this list can initially accept without growing its internal representation; must be at least 1
 
 
- 
 - 
Method Detail- 
addpublic void add(Object listener) Adds the given listener to this list. Has no effect if an identical listener is already registered.- Parameters:
- listener- the listener
 
 - 
clearpublic void clear() Removes all listeners from this list.
 - 
getListenerspublic Object[] getListeners() Returns an array containing all the registered listeners, in the order in which they were added.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. - Returns:
- the list of registered listeners
 
 - 
isEmptypublic boolean isEmpty() Returns whether this listener list is empty.- Returns:
- trueif there are no registered listeners, and- falseotherwise
 
 - 
removepublic void remove(Object listener) Removes the given listener from this list. Has no effect if an identical listener was not already registered.- Parameters:
- listener- the listener
 
 - 
sizepublic int size() Returns the number of registered listeners.- Returns:
- the number of registered listeners
 
 
- 
 
-