nl.knowledgeplaza.util.collection
Class ObservableSortedMap

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.TreeMap
          extended by nl.knowledgeplaza.util.collection.ObservableSortedMap
All Implemented Interfaces:
Serializable, Cloneable, Map, NavigableMap, SortedMap, ObservableCollection

public class ObservableSortedMap
extends TreeMap
implements ObservableCollection

The ObservableSortedMap subclasses the TreeMap 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

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Field Summary
protected  ArrayList listeners
          the observers of this collection
 
Constructor Summary
ObservableSortedMap()
          Constructs a new, empty map, sorted according to the keys' natural order.
ObservableSortedMap(Comparator c)
          Constructs a new, empty map, sorted according to the given comparator.
ObservableSortedMap(Map m)
          Constructs a new map containing the same mappings as the given map, sorted according to the keys' natural order.
ObservableSortedMap(SortedMap m)
          Constructs a new map containing the same mappings as the given SortedMap, sorted according to the same ordering.
 
Method Summary
 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.
 Object put(Object key, Object value)
          Calls the super class's corresponding method and fires a CollectionEvent.
 void putAll(Map t)
          Calls the super class's corresponding method and fires a CollectionEvent.
 Object remove(Object key)
          Calls the super class's corresponding method and fires a CollectionEvent.
 void removeCollectionListener(CollectionListener l)
          Removes the listener from this collection.
 
Methods inherited from class java.util.TreeMap
ceilingEntry, ceilingKey, clone, comparator, containsKey, containsValue, descendingKeySet, descendingMap, entrySet, firstEntry, firstKey, floorEntry, floorKey, get, headMap, headMap, higherEntry, higherKey, keySet, lastEntry, lastKey, lowerEntry, lowerKey, navigableKeySet, pollFirstEntry, pollLastEntry, size, subMap, subMap, tailMap, tailMap, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, isEmpty, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode, isEmpty
 

Field Detail

listeners

protected ArrayList listeners
the observers of this collection

Constructor Detail

ObservableSortedMap

public ObservableSortedMap()
Constructs a new, empty map, sorted according to the keys' natural order. All keys inserted into the map 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 map. If the user attempts to put a key into the map that violates this constraint (for example, the user attempts to put a string key into a map whose keys are integers), the put(Object key, Object value) call will throw a ClassCastException.


ObservableSortedMap

public ObservableSortedMap(Comparator c)
Constructs a new, empty map, sorted according to the given comparator. All keys inserted into the map must be mutually comparable by the given comparator: comparator.compare(k1, k2) must not throw a ClassCastException for any keys k1 and k2 in the map. If the user attempts to put a key into the map that violates this constraint, the put(Object key, Object value) call will throw a ClassCastException.

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

ObservableSortedMap

public ObservableSortedMap(Map m)
Constructs a new map containing the same mappings as the given map, sorted according to the keys' natural order. All keys inserted into the new map 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 map. This method runs in n*log(n) time.

Parameters:
m - the map whose mappings are to be placed in this map.

ObservableSortedMap

public ObservableSortedMap(SortedMap m)
Constructs a new map containing the same mappings as the given SortedMap, sorted according to the same ordering. This method runs in linear time.

Parameters:
m - the sorted map whose mappings are to be placed in this map, and whose comparator is to be used to sort this map.
Method Detail

put

public Object put(Object key,
                  Object value)
Calls the super class's corresponding method and fires a CollectionEvent.

Specified by:
put in interface Map
Overrides:
put in class TreeMap

remove

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

Specified by:
remove in interface Map
Overrides:
remove in class TreeMap

putAll

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

Specified by:
putAll in interface Map
Overrides:
putAll in class TreeMap

clear

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

Specified by:
clear in interface Map
Overrides:
clear in class TreeMap

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 © 2012 KnowledgePlaza. All Rights Reserved.