DESY ACOP Beans Home
com.cosylab.util
Class ListenerList
java.lang.Object
com.cosylab.util.ObjectList
com.cosylab.util.ListenerList
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Iterable, java.util.Collection, java.util.List
public class ListenerList
- extends ObjectList
A listener list is an efficient data structure for holding listeners. Its
design is based on the fact that listeners are extensively accessed for
event dispatching, but the collection of listeners changes rarely. Under
these circumstances (especilly rare invocations of
addListener()
and removeListener
methods) this
class is a good choice. It holds listeners in an array that is trimmed
every time the listener membership changes (which is quite inefficient). On
the other hand, accessing the elements of the array is quick, on the
condition and contract that the client does not modify the array being
returned. Also note that the array is of the correct run-time type
specified by the constructor of this class, and can therefore be cast. For
example, if you speficy WindowListener
as the RTT of this
list, you can perform WindowListener[] wla =
(WindowListener[])toArray()
without raising a
ClassCastException
. For cases where the listener membership
changes often, but events are dispatched rarely, use ArrayList
instead. This class is thread safe, there is no need for additional
synchronization. See also swing based listener registration for an
approach that is more time consuming during dispatching, but can store
different classes of listeners in a single array.
- Version:
- $id$
- Author:
- Gasper Tkacik
- See Also:
EventListenerList
,
Serialized Form
Constructor Summary |
ListenerList(java.lang.Class type)
Constructs a new instance of the listener list that will be used to hold
elements of type type . |
Methods inherited from class com.cosylab.util.ObjectList |
add, add, add, addAll, addAll, clear, contains, containsAll, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, set, size, subList, toArray, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
equals, hashCode |
ListenerList
public ListenerList(java.lang.Class type)
- Constructs a new instance of the listener list that will be used to hold
elements of type
type
. The specified class should be a
subclass of java.util.EventListener
.
- Parameters:
type
- a run-time type of the elements in this list
- Throws:
java.lang.NullPointerException
- DOCUMENT ME!
java.lang.IllegalArgumentException
- DOCUMENT ME!
Copyright © 2010. All Rights Reserved.