org.apache.pivot.util
Class ListenerList<T>

java.lang.Object
  extended by org.apache.pivot.util.ListenerList<T>
All Implemented Interfaces:
Iterable<T>
Direct Known Subclasses:
List.ListListenerList, Map.MapListenerList, Queue.QueueListenerList, Set.SetListenerList, Stack.StackListenerList

public abstract class ListenerList<T>
extends Object
implements Iterable<T>

Abstract base class for listener lists.

NOTE This class is not inherently thread safe. Subclasses that require thread-safe access should synchronize method access appropriately. Callers must manually synchronize on the listener list instance to ensure thread safety during iteration.


Constructor Summary
ListenerList()
           
 
Method Summary
 void add(T listener)
          Adds a listener to the list, if it has not previously been added.
 boolean contains(T listener)
          Tests the existence of a listener in the list.
 T get(int index)
          Get the indexed element in the list.
 int getLength()
          Get the number of elements in the list.
 boolean isEmpty()
          Tests the emptiness of the list.
 Iterator<T> iterator()
           
 void remove(T listener)
          Removes a listener from the list, if it has previously been added.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ListenerList

public ListenerList()
Method Detail

add

public void add(T listener)
Adds a listener to the list, if it has not previously been added.

Parameters:
listener -

remove

public void remove(T listener)
Removes a listener from the list, if it has previously been added.

Parameters:
listener -

contains

public boolean contains(T listener)
Tests the existence of a listener in the list.

Parameters:
listener -
Returns:
true if the listener exists in the list; false, otherwise.

isEmpty

public boolean isEmpty()
Tests the emptiness of the list.

Returns:
true if the list contains no listeners; false, otherwise.

getLength

public int getLength()
Get the number of elements in the list.

Returns:
the number of elements.

get

public T get(int index)
Get the indexed element in the list.

Returns:
the element at position index or throw an IndexOutOfBoundsException

iterator

public Iterator<T> iterator()
Specified by:
iterator in interface Iterable<T>

toString

public String toString()
Overrides:
toString in class Object