com.day.util
Class ListenerList

java.lang.Object
  extended by com.day.util.ListenerList

public class ListenerList
extends Object

The ListenerList class provides a utility to maintain lists of registered listeners. It is fairly lightweight and should not impose to much memory overhead.

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);
 }
 

Since:
iguana
Version:
$Revision: 1.3 $, $Date: 2004-08-30 08:35:44 +0200 (Mon, 30 Aug 2004) $
Author:
fmeschbe

Constructor Summary
ListenerList()
          Creates an instance of this listener list class.
 
Method Summary
 boolean addListener(Object listener)
          Adds a listener to the list of listeners if it is not yet registered in the list.
 void clear()
          Clears the list of registered listeners.
 Object[] getListeners()
          Returns the list of registered listeners.
 Object[] getListeners(Class requestedType)
          Returns the list of registered listeners in an array of the reqeusted runtime type.
 boolean removeListener(Object listener)
          Removes a listener from the list of listeners if it is contained.
 int size()
          Returns the number of currently registered listeners.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListenerList

public ListenerList()
Creates an instance of this listener list class.

Method Detail

addListener

public boolean addListener(Object listener)
Adds a listener to the list of listeners if it is not yet registered in the list.

Parameters:
listener - The listener to add to the list. If null nothing is done.
Returns:
true if the listener has been added to the list

removeListener

public boolean removeListener(Object listener)
Removes a listener from the list of listeners if it is contained.

Parameters:
listener - The listener to remove from the list. If null nothing is done.
Returns:
true if the listener has been added to the list

clear

public void clear()
Clears the list of registered listeners.


size

public int size()
Returns the number of currently registered listeners.


getListeners

public Object[] getListeners()
Returns the list of registered listeners. Note that this method returns the same array for two subsequent calls if no listeners have been added or removed in the mean time. This also means, that callers of this method MUST NOT modify the array returned.


getListeners

public Object[] getListeners(Class requestedType)
Returns the list of registered listeners in an array of the reqeusted runtime type. Note that this method returns the same array for two subsequent calls if no listeners have been added or removed in the mean time and if the element type of is assignment compatible. This also means, that callers of this method MUST NOT modify the array returned.

Parameters:
requestedType - The runtime type of the components of the array to return.
Throws:
ArrayStoreException - if the runtime type is not a supertype of the runtime type of every element in this list.


Copyright © 2011-2013 Adobe Systems Incorporated. All Rights Reserved.