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:
Serializable, Cloneable, Iterable<T>, Collection<T>, List<T>, RandomAccess, ObservableCollection<T>

public class ObservableList<T>
extends 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
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ObservableList()
          Constructs an empty list with an initial capacity of ten.
ObservableList(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(Collection c)
          Calls the super class's corresponding method and fires a CollectionEvent.
 boolean addAll(int index, 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.
 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(Object o)
          Calls the super class's corresponding method and fires a CollectionEvent.
 boolean removeAll(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(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
 

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(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 Collection<T>
Specified by:
add in interface List<T>
Overrides:
add in class ArrayList<T>

remove

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

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

addAll

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

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

addAll

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

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

removeAll

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

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

clear

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

Specified by:
clear in interface Collection<T>
Specified by:
clear in interface List<T>
Overrides:
clear in class 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 List<T>
Overrides:
set in class 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 List<T>
Overrides:
add in class ArrayList<T>

remove

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

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

retainAll

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

Specified by:
retainAll in interface Collection<T>
Specified by:
retainAll in interface List<T>
Overrides:
retainAll in class 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 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 © 2012 KnowledgePlaza. All Rights Reserved.