Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.eclipse.osgi.framework.eventmgr
Class EventListeners  view EventListeners download EventListeners.java

java.lang.Object
  extended byorg.eclipse.osgi.framework.eventmgr.EventListeners

public class EventListeners
extends java.lang.Object

This class manages a list of listeners. Listeners may be added or removed as necessary.


Field Summary
private  boolean copyOnWrite
          If true and about to modify the list, then the list must be copied first.
private static ListElement[] emptyArray
          The empty array singleton instance, returned by getListeners() when size == 0.
private  int initialCapacity
          The initial capacity of the list.
private  ListElement[] list
          The list of elements.
private  int size
          The current number of elements.
 
Constructor Summary
EventListeners()
          Creates a listener list with an initial capacity of 10.
EventListeners(int capacity)
          Creates a listener list with the given initial capacity.
 
Method Summary
 void addListener(java.lang.Object listener, java.lang.Object listenerObject)
          Add a listener to the list.
private  void copyList(int i)
          Copy the array.
(package private)  ListElement[] getListeners()
          Return the list of (listener, listenerObject) pairs.
 void removeAllListeners()
          Remove all listeners from the list.
 void removeListener(java.lang.Object listener)
          Remove a listener from the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

emptyArray

private static final ListElement[] emptyArray
The empty array singleton instance, returned by getListeners() when size == 0.


initialCapacity

private final int initialCapacity
The initial capacity of the list. Always >= 1.


list

private ListElement[] list
The list of elements. Initially null but initialized to an array of size initialCapacity the first time an element is added. Maintains invariants: list != null IFF size != 0 list[size] == null for all i < size: list[i] != null Access to this field must be protected by a synchronized region.


size

private int size
The current number of elements. Maintains invariant: 0 <= size <= list.length. Access to this field must be protected by a synchronized region.


copyOnWrite

private boolean copyOnWrite
If true and about to modify the list, then the list must be copied first. Access to this field must be protected by a synchronized region.

Constructor Detail

EventListeners

public EventListeners()
Creates a listener list with an initial capacity of 10.


EventListeners

public EventListeners(int capacity)
Creates a listener list with the given initial capacity.

Method Detail

addListener

public void addListener(java.lang.Object listener,
                        java.lang.Object listenerObject)
Add a listener to the list. If a listener object is already in the list, then it is replaced.


removeListener

public void removeListener(java.lang.Object listener)
Remove a listener from the list.


removeAllListeners

public void removeAllListeners()
Remove all listeners from the list.


getListeners

ListElement[] getListeners()
Return the list of (listener, listenerObject) pairs. Package private method. The array may be longer than the number of pairs in the array. The end of the pairs is signalled by a null element or end of array. This array must not be modified by anyone and should not be exposed outside of this package. To reduce memory allocations, the internal array is shared with the rest of this package. However an array returned by this method must not be modified in anyway.


copyList

private void copyList(int i)
Copy the array.