nl.knowledgeplaza.util.collection
Class ObservableSortedSet

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by java.util.TreeSet
              extended by nl.knowledgeplaza.util.collection.ObservableSortedSet
All Implemented Interfaces:
Serializable, Cloneable, Iterable, Collection, Set, SortedSet, ObservableCollection

public class ObservableSortedSet
extends TreeSet
implements ObservableCollection

The ObservableSortedSet subclasses the TreeSet 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.

See Also:
Serialized Form

Field Summary
protected  ArrayList listeners
          the observers of this collection
 
Constructor Summary
ObservableSortedSet()
          Constructs a new, empty set, sorted according to the elements' natural order.
ObservableSortedSet(Collection c)
          Constructs a new set containing the elements in the specified collection, sorted according to the elements' natural order.
ObservableSortedSet(Comparator c)
          Constructs a new, empty set, sorted according to the specified comparator.
ObservableSortedSet(SortedSet s)
          Constructs a new set containing the same elements as the specified sorted set, sorted according to the same ordering.
 
Method Summary
 boolean add(Object 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.
 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.
 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.
 
Methods inherited from class java.util.TreeSet
clone, comparator, contains, first, headSet, isEmpty, iterator, last, size, subSet, tailSet
 
Methods inherited from class java.util.AbstractSet
equals, hashCode
 
Methods inherited from class java.util.AbstractCollection
containsAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
containsAll, equals, hashCode, toArray, toArray
 

Field Detail

listeners

protected ArrayList listeners
the observers of this collection

Constructor Detail

ObservableSortedSet

public ObservableSortedSet()
Constructs a new, empty set, sorted according to the elements' natural order.


ObservableSortedSet

public ObservableSortedSet(Comparator c)
Constructs a new, empty set, sorted according to the specified comparator. All elements inserted into the set must be mutually comparable by the specified comparator: comparator.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the set. If the user attempts to add an element to the set that violates this constraint, the add(Object) call will throw a ClassCastException.

Parameters:
c - the comparator that will be used to sort this set. A null value indicates that the elements' natural ordering should be used.

ObservableSortedSet

public ObservableSortedSet(Collection c)
Constructs a new set containing the elements in the specified collection, sorted according to the elements' natural order. All keys inserted into the set must implement the Comparable interface. Furthermore, all such keys must be mutually comparable: k1.compareTo(k2) must not throw a ClassCastException for any elements k1 and k2 in the set.

Parameters:
c - The elements that will comprise the new set.

ObservableSortedSet

public ObservableSortedSet(SortedSet s)
Constructs a new set containing the same elements as the specified sorted set, sorted according to the same ordering.

Parameters:
s - sorted set whose elements will comprise the new set.
Method Detail

add

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

Specified by:
add in interface Collection
Specified by:
add in interface Set
Overrides:
add in class TreeSet

remove

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

Specified by:
remove in interface Collection
Specified by:
remove in interface Set
Overrides:
remove in class TreeSet

addAll

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

Specified by:
addAll in interface Collection
Specified by:
addAll in interface Set
Overrides:
addAll in class TreeSet

removeAll

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

Specified by:
removeAll in interface Collection
Specified by:
removeAll in interface Set
Overrides:
removeAll in class AbstractSet

clear

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

Specified by:
clear in interface Collection
Specified by:
clear in interface Set
Overrides:
clear in class TreeSet

retainAll

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

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