nl.knowledgeplaza.util.collection
Class ObservableList<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<T>
              extended by nl.knowledgeplaza.util.collection.ObservableList<T>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>, java.util.RandomAccess, ObservableCollection<T>

public class ObservableList<T>
extends java.util.ArrayList<T>
implements ObservableCollection<T>

The ObservableList subclasses the ArrayList and overrides all the functions that change the internally stored collection. In the overridden function, it simply calls the super class's function and fires a CollectionEvent to let observers know the collection has changed. TOEU 2007-01-29: this implementation sucks! It does not update all changes, just that there has been a change. Made some improvements.

See Also:
Serialized Form

Field Summary
protected  java.util.ArrayList<CollectionListener> iListeners
          the observers of this collection
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ObservableList()
          Constructs an empty list with an initial capacity of ten.
ObservableList(java.util.Collection<T> c)
          Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.
ObservableList(int initialCapacity)
          Constructs an empty list with the specified initial capacity.
 
Method Summary
 void add(int index, T element)
          Calls the super class's corresponding method and fires a CollectionEvent.
 boolean add(T o)
          Calls the super class's corresponding method and fires a CollectionEvent.
 boolean addAll(java.util.Collection c)
          Calls the super class's corresponding method and fires a CollectionEvent.
 boolean addAll(int index, java.util.Collection c)
          Calls the super class's corresponding method and fires a CollectionEvent.
 void addCollectionListener(CollectionListener l)
          Adds a listener to this collection.
 void clear()
          Calls the super class's corresponding method and fires a CollectionEvent.
protected  void fireCollectionEvent(CollectionEvent e)
          Fires a CollectionEvent to all listeners.
 java.lang.Object getObservedCollection()
          To access the collection that is being observed.
 T remove(int index)
          Calls the super class's corresponding method and fires a CollectionEvent.
 boolean remove(java.lang.Object o)
          Calls the super class's corresponding method and fires a CollectionEvent.
 boolean removeAll(java.util.Collection c)
          Calls the super class's corresponding method and fires a CollectionEvent.
 void removeCollectionListener(CollectionListener l)
          Removes the listener from this collection.
 boolean retainAll(java.util.Collection c)
          Calls the super class's corresponding method and fires a CollectionEvent.
 T set(int index, T element)
          Calls the super class's corresponding method and fires a CollectionEvent.
 
Methods inherited from class java.util.ArrayList
clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, removeRange, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, subList
 

Field Detail

iListeners

protected java.util.ArrayList<CollectionListener> iListeners
the observers of this collection

Constructor Detail

ObservableList

public ObservableList(int initialCapacity)
Constructs an empty list with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity of the list

ObservableList

public ObservableList()
Constructs an empty list with an initial capacity of ten.


ObservableList

public ObservableList(java.util.Collection<T> c)
Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.

Parameters:
c - the collection whose elements are to be placed into this list.
Method Detail

add

public boolean add(T o)
Calls the super class's corresponding method and fires a CollectionEvent.

Specified by:
add in interface java.util.Collection<T>
Specified by:
add in interface java.util.List<T>
Overrides:
add in class java.util.ArrayList<T>

remove

public boolean remove(java.lang.Object o)
Calls the super class's corresponding method and fires a CollectionEvent.

Specified by:
remove in interface java.util.Collection<T>
Specified by:
remove in interface java.util.List<T>
Overrides:
remove in class java.util.ArrayList<T>

addAll

public boolean addAll(java.util.Collection c)
Calls the super class's corresponding method and fires a CollectionEvent.

Specified by:
addAll in interface java.util.Collection<T>
Specified by:
addAll in interface java.util.List<T>
Overrides:
addAll in class java.util.ArrayList<T>

addAll

public boolean addAll(int index,
                      java.util.Collection c)
Calls the super class's corresponding method and fires a CollectionEvent.

Specified by:
addAll in interface java.util.List<T>
Overrides:
addAll in class java.util.ArrayList<T>

removeAll

public boolean removeAll(java.util.Collection c)
Calls the super class's corresponding method and fires a CollectionEvent.

Specified by:
removeAll in interface java.util.Collection<T>
Specified by:
removeAll in interface java.util.List<T>
Overrides:
removeAll in class java.util.AbstractCollection<T>

clear

public void clear()
Calls the super class's corresponding method and fires a CollectionEvent.

Specified by:
clear in interface java.util.Collection<T>
Specified by:
clear in interface java.util.List<T>
Overrides:
clear in class java.util.ArrayList<T>

set

public T set(int index,
             T element)
Calls the super class's corresponding method and fires a CollectionEvent.

Specified by:
set in interface java.util.List<T>
Overrides:
set in class java.util.ArrayList<T>

add

public void add(int index,
                T element)
Calls the super class's corresponding method and fires a CollectionEvent.

Specified by:
add in interface java.util.List<T>
Overrides:
add in class java.util.ArrayList<T>

remove

public T remove(int index)
Calls the super class's corresponding method and fires a CollectionEvent.

Specified by:
remove in interface java.util.List<T>
Overrides:
remove in class java.util.ArrayList<T>

retainAll

public boolean retainAll(java.util.Collection c)
Calls the super class's corresponding method and fires a CollectionEvent.

Specified by:
retainAll in interface java.util.Collection<T>
Specified by:
retainAll in interface java.util.List<T>
Overrides:
retainAll in class java.util.AbstractCollection<T>

addCollectionListener

public void addCollectionListener(CollectionListener l)
Adds a listener to this collection.

Specified by:
addCollectionListener in interface ObservableCollection<T>
Parameters:
l - the CollectionListener

removeCollectionListener

public void removeCollectionListener(CollectionListener l)
Removes the listener from this collection.

Specified by:
removeCollectionListener in interface ObservableCollection<T>
Parameters:
l - the CollectionListener

fireCollectionEvent

protected void fireCollectionEvent(CollectionEvent e)
Fires a CollectionEvent to all listeners.

Parameters:
e - the CollectionEvent

getObservedCollection

public java.lang.Object getObservedCollection()
To access the collection that is being observed. Unfortunately not all collections implement one interface.

Specified by:
getObservedCollection in interface ObservableCollection<T>
Returns:
Unfortunately not all collections implement one interface, so the return type depends on the observed collection.


Copyright © 2010. All Rights Reserved.