nl.knowledgeplaza.util.collection
Class ObservableSet

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

public class ObservableSet
extends HashSet
implements ObservableCollection

The ObservableSet subclasses the HashSet 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
ObservableSet()
          Constructs a new, empty set; the backing HashMap instance has default initial capacity (16) and load factor (0.75).
ObservableSet(Collection c)
          Constructs a new set containing the elements in the specified collection.
ObservableSet(int initialCapacity)
          Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and default load factor, which is 0.75.
ObservableSet(int initialCapacity, float loadFactor)
          Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and the specified load factor.
 
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.HashSet
clone, contains, isEmpty, iterator, size
 
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

ObservableSet

public ObservableSet()
Constructs a new, empty set; the backing HashMap instance has default initial capacity (16) and load factor (0.75).


ObservableSet

public ObservableSet(Collection c)
Constructs a new set containing the elements in the specified collection. The HashMap is created with default load factor (0.75) and an initial capacity sufficient to contain the elements in the specified collection.

Parameters:
c - the collection whose elements are to be placed into this set.

ObservableSet

public ObservableSet(int initialCapacity,
                     float loadFactor)
Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and the specified load factor.

Parameters:
initialCapacity - the initial capacity of the hash map.
loadFactor - the load factor of the hash map.

ObservableSet

public ObservableSet(int initialCapacity)
Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and default load factor, which is 0.75.

Parameters:
initialCapacity - the initial capacity of the hash table.
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 HashSet

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 HashSet

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 AbstractCollection

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 HashSet

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