public interface IlvEventListenerCollection<L extends EventListener>
IlvEventListenerCollection
defines the behavior of a thread-safe
collection of event listeners. A class that fires events to a specific listener
interface can use an IlvEventListenerCollection
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); } } }
Modifier and Type | Method and Description |
---|---|
void |
addListener(L listener)
Adds the specified listener to this collection.
|
boolean |
contains(L listener)
Returns whether this collection contains the specified listener.
|
Iterator<L> |
getListeners()
Returns an iterator over the event listeners.
|
void |
removeListener(L listener)
Removes the specified listener from this collection.
|
void |
save(ObjectOutputStream s,
String k)
Serializes the collection of event listeners as a series of key-value pairs.
|
void addListener(L listener)
listener
- The listener.void removeListener(L listener)
listener
- The listener.Iterator<L> getListeners()
boolean contains(L listener)
listener
- The listener.true
if this collection contains listener
,
otherwise false
.void save(ObjectOutputStream s, String k) throws IOException
s
- The object output stream to write the event listeners.k
- A key string that is written in front of
each listener to identify its type.IOException
© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.