org.deduced.utilities
Class WeakList<E>

java.lang.Object
  extended by org.deduced.utilities.WeakList<E>
Type Parameters:
E - the type of element contained in the list

public class WeakList<E>
extends java.lang.Object

WeakList this list holds a weak reference to all the elements it contains. The iterator will never return a null value. The weak list matches object by object identity. Not by the equal method.

Author:
Steve McDuff

Nested Class Summary
static class WeakList.WeakIterator<E>
          Class representing an iterator on a weak list.
 
Field Summary
private  java.util.List<java.lang.ref.WeakReference<E>> listenerList
          The list of Listener in weak references
 
Constructor Summary
WeakList()
          constructor
 
Method Summary
 void add(E l)
          add an object to the list
private  void cleanList()
          clean the List of expired weak pointers
 void clear()
          clear the list
 boolean contains(java.lang.Object o)
          test if an object is contained in this list
protected  java.util.List<java.lang.ref.WeakReference<E>> getListenerList()
          get Listener List
 boolean isEmpty()
           
 java.util.Iterator<E> iterator()
          fetch an iterator to browse the list
 java.lang.Object remove(java.lang.Object l)
          remove an object from the list
 int size()
           
 java.lang.Object[] toArray()
           
<T> T[]
toArray(java.lang.Class<T> arrayClass)
          convert the list to an array of the type specified in the input type.
<T> T[]
toArray(T[] input)
          convert the list to an array of the type specified in the input type.
<T> T[]
toArray(T[] input, java.lang.Class<T> arrayClass)
          convert the list to an array of the type specified in the input type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listenerList

private transient java.util.List<java.lang.ref.WeakReference<E>> listenerList
The list of Listener in weak references

Constructor Detail

WeakList

public WeakList()
constructor

Method Detail

getListenerList

protected java.util.List<java.lang.ref.WeakReference<E>> getListenerList()
get Listener List

Returns:
the listener list

isEmpty

public boolean isEmpty()
Returns:
true if the list is empty

cleanList

private void cleanList()
clean the List of expired weak pointers


contains

public boolean contains(java.lang.Object o)
test if an object is contained in this list

Parameters:
o - the object that might be in the list
Returns:
true if the object is held by this list

size

public int size()
Returns:
the list size

add

public void add(E l)
add an object to the list

Parameters:
l - the object to add

remove

public java.lang.Object remove(java.lang.Object l)
remove an object from the list

Parameters:
l - the object to remove
Returns:
the removed object

iterator

public java.util.Iterator<E> iterator()
fetch an iterator to browse the list

Returns:
the iterator

toArray

public java.lang.Object[] toArray()
Returns:
the listener list. Some elements may be null if they were garbage collected because of the weak reference.

toArray

public <T> T[] toArray(T[] input)
convert the list to an array of the type specified in the input type.

Type Parameters:
T - the type of array to use
Parameters:
input - the array to fill. If the array is too small, a different array of the right size will be returned.
Returns:
the list as an array. The array might contain null values that were garbage collected at some point.

toArray

public <T> T[] toArray(java.lang.Class<T> arrayClass)
convert the list to an array of the type specified in the input type.

Type Parameters:
T - the type of array to use
Parameters:
arrayClass - the class of the array container
Returns:
the list as an array. The array might contain null values that were garbage collected at some point.

toArray

public <T> T[] toArray(T[] input,
                       java.lang.Class<T> arrayClass)
convert the list to an array of the type specified in the input type.

Type Parameters:
T - the type of array to use
Parameters:
input - the array to fill. If the array is too small, a different array of the right size will be returned.
arrayClass - the class of the array container
Returns:
the list as an array. The array might contain null values that were garbage collected at some point.

clear

public void clear()
clear the list