fcmodeler.util
Class ObservableSet

java.lang.Object
  |
  +--fcmodeler.util.ObservableSet
All Implemented Interfaces:
java.util.Collection, java.util.Set

public class ObservableSet
extends java.lang.Object
implements java.util.Set

A set that notifies listeners of any modications. Other classes can implement the SetChangeListener interface, and register with this class to receive notifiactions of any changes to the wrapped set. Note that listeners are notified after the set has already been modified.

Since:
JDK1.3
Version:
$Revision: 1.1 $
Author:
Julie Dickerson , Zach Cox

Constructor Summary
ObservableSet()
          Creates a new ObservableSet using a java.util.HashSet.
ObservableSet(java.util.Set set)
          Creates a new ObservableSet that wraps the specified set.
 
Method Summary
 boolean add(java.lang.Object obj)
          Adds the specified element to this set if it is not already present and notifies listeners of the addition.
 boolean addAll(java.util.Collection collection)
          Adds all of the elements in the specified collection to this set if they're not already present and notifies listeners of any elements that are added.
 void addSetChangeListener(SetChangeListener listener)
          Registers the specified listener with this set.
 void clear()
          Removes all of the elements from this set and notifies listeners of the removals.
 boolean contains(java.lang.Object obj)
          Returns true if this set contains the specified element.
 boolean containsAll(java.util.Collection collection)
          Returns true if this set contains all of the elements of the specified collection.
 boolean equals(java.lang.Object obj)
          Compares the specified object with this set for equality.
protected  void fireElementAdded(java.lang.Object element)
          Notifies listeners that the specified element has been added to this set.
protected  void fireElementRemoved(java.lang.Object element)
          Notifies listeners that the specified element has been removed from this set.
 java.util.Set getSet()
          Returns the set that this set wraps.
 java.util.Iterator getSetChangeListeners()
          Returns an iterator over all listeners for this set.
 int hashCode()
          Returns the hash code value for this set.
 boolean isEmpty()
          Returns true if this set contains no elements.
 java.util.Iterator iterator()
          Returns an iterator over the elements in this set
 boolean remove(java.lang.Object obj)
          Removes the specified element from this set if it is present and notifies listeners of the removal.
 boolean removeAll(java.util.Collection collection)
          Removes from this set all of its elements that are contained in the specified collection and notifies listeners of the removals.
 void removeSetChangeListener(SetChangeListener listener)
          Stops the specified listener from receiving notifications from this set.
 boolean retainAll(java.util.Collection collection)
          Retains only the elements in this set that are contained in the specified collection and notifies listeners of the removals.
 int size()
          Returns the number of elements in this set.
 java.lang.Object[] toArray()
          Returns an array containing all of the elements in this set.
 java.lang.Object[] toArray(java.lang.Object[] obj)
          Returns an array containing all of the elements in this set whose runtime type is that of the specified array.
 java.lang.String toString()
          Returns a string representation of this set.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ObservableSet

public ObservableSet()
Creates a new ObservableSet using a java.util.HashSet.

ObservableSet

public ObservableSet(java.util.Set set)
Creates a new ObservableSet that wraps the specified set.
Parameters:
set - the set to notify listeners of changes to.
Method Detail

add

public boolean add(java.lang.Object obj)
Adds the specified element to this set if it is not already present and notifies listeners of the addition.
Specified by:
add in interface java.util.Set
Parameters:
obj - the element to add.
Returns:
true if the element was added.

addAll

public boolean addAll(java.util.Collection collection)
Adds all of the elements in the specified collection to this set if they're not already present and notifies listeners of any elements that are added.
Specified by:
addAll in interface java.util.Set
Parameters:
collection - the collection whose elements are to be added to this set.
Returns:
true if any of the elements were added.

addSetChangeListener

public void addSetChangeListener(SetChangeListener listener)
Registers the specified listener with this set.
Parameters:
listener - the listener to register with this set.

clear

public void clear()
Removes all of the elements from this set and notifies listeners of the removals.
Specified by:
clear in interface java.util.Set

contains

public boolean contains(java.lang.Object obj)
Returns true if this set contains the specified element.
Specified by:
contains in interface java.util.Set
Parameters:
obj - element to test for containment.
Returns:
true if this set contains the specified element.

containsAll

public boolean containsAll(java.util.Collection collection)
Returns true if this set contains all of the elements of the specified collection.
Specified by:
containsAll in interface java.util.Set
Parameters:
collection - the collection to test for containment.
Returns:
true if this set contains all of the elements of the specified collection.

equals

public boolean equals(java.lang.Object obj)
Compares the specified object with this set for equality.
Specified by:
equals in interface java.util.Set
Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to test for equality.
Returns:
true if the specified object is equal to this set.

fireElementAdded

protected void fireElementAdded(java.lang.Object element)
Notifies listeners that the specified element has been added to this set.
Parameters:
element - the element added to this set.

fireElementRemoved

protected void fireElementRemoved(java.lang.Object element)
Notifies listeners that the specified element has been removed from this set.
Parameters:
element - the element that was removed.

getSet

public java.util.Set getSet()
Returns the set that this set wraps.
Returns:
the set that this set wraps.

getSetChangeListeners

public java.util.Iterator getSetChangeListeners()
Returns an iterator over all listeners for this set.
Returns:
an iterator over all listeners for this set.

hashCode

public int hashCode()
Returns the hash code value for this set.
Specified by:
hashCode in interface java.util.Set
Overrides:
hashCode in class java.lang.Object
Returns:
the hash code for this set.

isEmpty

public boolean isEmpty()
Returns true if this set contains no elements.
Specified by:
isEmpty in interface java.util.Set
Returns:
true if this set contains no elements.

iterator

public java.util.Iterator iterator()
Returns an iterator over the elements in this set
Specified by:
iterator in interface java.util.Set
Returns:
an iterator over the elements in this set

remove

public boolean remove(java.lang.Object obj)
Removes the specified element from this set if it is present and notifies listeners of the removal.
Specified by:
remove in interface java.util.Set
Parameters:
obj - the element to remove from this set.
Returns:
true if the element was removed.

removeAll

public boolean removeAll(java.util.Collection collection)
Removes from this set all of its elements that are contained in the specified collection and notifies listeners of the removals.
Specified by:
removeAll in interface java.util.Set
Parameters:
collection - the collection whose elements are to be removed from this set.
Returns:
true if any of the collection's elements were removed.

removeSetChangeListener

public void removeSetChangeListener(SetChangeListener listener)
Stops the specified listener from receiving notifications from this set.
Parameters:
listener - the listener to stop receiving notifications from this set.

retainAll

public boolean retainAll(java.util.Collection collection)
Retains only the elements in this set that are contained in the specified collection and notifies listeners of the removals.
Specified by:
retainAll in interface java.util.Set
Parameters:
collection - collection that defines which elements this set will retain.
Returns:
true if any elements were removed from this set.

size

public int size()
Returns the number of elements in this set.
Specified by:
size in interface java.util.Set
Returns:
the number of elements in this set.

toArray

public java.lang.Object[] toArray()
Returns an array containing all of the elements in this set.
Specified by:
toArray in interface java.util.Set
Returns:
an array containing all of the elements in this set.

toArray

public java.lang.Object[] toArray(java.lang.Object[] obj)
Returns an array containing all of the elements in this set whose runtime type is that of the specified array.
Specified by:
toArray in interface java.util.Set
Parameters:
obj - the array into which the elements of this set are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
Returns:
an array containing the elements of this set.

toString

public java.lang.String toString()
Returns a string representation of this set.
Overrides:
toString in class java.lang.Object
Returns:
a string representation of this set.