nl.knowledgeplaza.util.collection
Class ObservableList

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

public class ObservableList
extends java.util.ArrayList
implements ObservableCollection

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 listeners
          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 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, java.lang.Object element)
          Calls the super class's corresponding method and fires a CollectionEvent.
 boolean add(java.lang.Object 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.
 java.lang.Object 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.
 java.lang.Object set(int index, java.lang.Object 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

listeners

protected java.util.ArrayList listeners
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 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(java.lang.Object o)
Calls the super class's corresponding method and fires a CollectionEvent.

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

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
Specified by:
remove in interface java.util.List
Overrides:
remove in class java.util.ArrayList

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
Specified by:
addAll in interface java.util.List
Overrides:
addAll in class java.util.ArrayList

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
Overrides:
addAll in class java.util.ArrayList

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
Specified by:
removeAll in interface java.util.List
Overrides:
removeAll in class java.util.AbstractCollection

clear

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

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

set

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

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

add

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

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

remove

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

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

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
Specified by:
retainAll in interface java.util.List
Overrides:
retainAll in class java.util.AbstractCollection

addCollectionListener

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

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

removeCollectionListener

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

Specified by:
removeCollectionListener in interface ObservableCollection
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
Returns:
Unfortunately not all collections implement one interface, so the return type depends on the observed collection.


Copyright © 2010. All Rights Reserved.