nl.knowledgeplaza.util.collection
Class ObservableMap

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap
          extended by nl.knowledgeplaza.util.collection.ObservableMap
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map, ObservableCollection

public class ObservableMap
extends java.util.HashMap
implements ObservableCollection

The ObservableMap subclasses the HashMap 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  java.util.ArrayList listeners
          the observers of this collection
 
Constructor Summary
ObservableMap()
          Constructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75).
ObservableMap(int initialCapacity)
          Constructs an empty HashMap with the specified initial capacity and the default load factor (0.75).
ObservableMap(int initialCapacity, float loadFactor)
          Constructs an empty HashMap with the specified initial capacity and load factor.
ObservableMap(java.util.Map m)
          Constructs a new HashMap with the same mappings as the specified Map.
 
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.
 java.lang.Object getObservedCollection()
          To access the collection that is being observed.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Calls the super class's corresponding method and fires a CollectionEvent.
 void putAll(java.util.Map t)
          Calls the super class's corresponding method and fires a CollectionEvent.
 java.lang.Object remove(java.lang.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.HashMap
clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

listeners

protected java.util.ArrayList listeners
the observers of this collection

Constructor Detail

ObservableMap

public ObservableMap(int initialCapacity,
                     float loadFactor)
Constructs an empty HashMap with the specified initial capacity and load factor.

Parameters:
initialCapacity - The initial capacity.
loadFactor - The load factor.

ObservableMap

public ObservableMap(int initialCapacity)
Constructs an empty HashMap with the specified initial capacity and the default load factor (0.75).

Parameters:
initialCapacity - the initial capacity.

ObservableMap

public ObservableMap()
Constructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75).


ObservableMap

public ObservableMap(java.util.Map m)
Constructs a new HashMap with the same mappings as the specified Map. The HashMap is created with default load factor (0.75) and an initial capacity sufficient to hold the mappings in the specified Map.

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

put

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

Specified by:
put in interface java.util.Map
Overrides:
put in class java.util.HashMap

remove

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

Specified by:
remove in interface java.util.Map
Overrides:
remove in class java.util.HashMap

putAll

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

Specified by:
putAll in interface java.util.Map
Overrides:
putAll in class java.util.HashMap

clear

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

Specified by:
clear in interface java.util.Map
Overrides:
clear in class java.util.HashMap

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.

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.