public class IlvEventListenerSet<L extends EventListener> extends IlvAbstractEventListenerCollection<L>
IlvEventListenerSet
implements a thread-safe collection of
event listeners backed by a hashed set. Some of the pros and cons of using
an IlvEventListenerSet
to manage the event dispatch system
for a class are:
IlvEventListenerSet
has nearly constant performance for
adding and removing event listeners.Here is an example that shows how a class can use an
IlvEventListenerSet
for registering event
listeners and dispatching events to them:
public class MyClass { IlvEventListenerCollection<XYZListener> xyzListeners = new IlvEventListenerSet<XYZListener>(); public void addXYZListener(XYZListener aListener) { xyzListeners.addListener(aListener); } public void removeXYZListener(XYZListener aListener) { xyzListeners.removeListener(aListener); } public void notifyXYZListeners () { XYZEvent event = new XYZEvent(this); for (Iterator<XYZListener> i = xyzListeners.getListeners(); i.hasNext(); ) { XYZListener xyzListener = i.next(); xyzListener.xyzHappened(event); } } }
Constructor and Description |
---|
IlvEventListenerSet()
Creates a new
IlvEventListenerSet . |
Modifier and Type | Method and Description |
---|---|
protected Collection<L> |
cloneListeners()
Returns a copy of the collection of event listeners.
|
protected void |
initListeners()
Initializes the collection of event listeners.
|
addListener, contains, getListeners, removeListener, save, size
public IlvEventListenerSet()
IlvEventListenerSet
.protected void initListeners()
initListeners
in class IlvAbstractEventListenerCollection<L extends EventListener>
protected Collection<L> cloneListeners()
cloneListeners
in class IlvAbstractEventListenerCollection<L extends EventListener>
© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.