org.coffeecrew.mobile.oop.util
Class Observable

java.lang.Object
  extended by org.coffeecrew.mobile.oop.util.Observable
Direct Known Subclasses:
BulkObjectPusher, ObjectPusher, ObjectReceiver

public class Observable
extends java.lang.Object

This class is intended to be used if you want your object to be observable. It reimplements java.util.Observable so you can also work with the observer pattern using J2ME. This class also works in a J2SE environment and can be used as a replacement for java.util.Observable

Since:
0.1

Constructor Summary
Observable()
          Creates a new instance of Observable with zero observers attached
 
Method Summary
 void addObserver(Observer observer)
          Adds an observer to this object which should be informed if the state of this object changes.
protected  void clearChanged()
          Should be called if the state of the object is no longer changed or if all attached observer have been notified about the state change.
 int countObservers()
          Returns the number of observers that are attached to this object
 void deleteObserver(Observer observer)
          Deletes the specified observer from the list of observers so no more updates will be delivered to the observer
 void deleteObservers()
          Removes all currently attached observers from this object
 boolean hasChanged()
          If any attribute within the object changed this method returns true
 void notifyObservers()
          Notifies attached observers that the state of this objet has changed
 void notifyObservers(java.lang.Object arg)
          Notifies attached observers that the state of this objet has changed
protected  void setChanged()
          Mark the object as having changed it's state.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Observable

public Observable()
Creates a new instance of Observable with zero observers attached

Method Detail

addObserver

public void addObserver(Observer observer)
Adds an observer to this object which should be informed if the state of this object changes. The observer added should not already be added. There is no need to synchronize this, because the java.util.Vector already synchronizes adding of elements.

Parameters:
observer - The observer which should be added.
Since:
0.1

clearChanged

protected void clearChanged()
Should be called if the state of the object is no longer changed or if all attached observer have been notified about the state change.


countObservers

public int countObservers()
Returns the number of observers that are attached to this object

Returns:
The number of observers currently attached to this object

deleteObserver

public void deleteObserver(Observer observer)
Deletes the specified observer from the list of observers so no more updates will be delivered to the observer

Parameters:
observer - The observer to be deleted

deleteObservers

public void deleteObservers()
Removes all currently attached observers from this object


hasChanged

public boolean hasChanged()
If any attribute within the object changed this method returns true

Returns:
true if the state of the object has changed otherwise false
See Also:
setChanged(), clearChanged()

notifyObservers

public void notifyObservers()
Notifies attached observers that the state of this objet has changed

See Also:
notifyObservers(Object)

notifyObservers

public void notifyObservers(java.lang.Object arg)
Notifies attached observers that the state of this objet has changed

Parameters:
arg - Argument to the observers update method

setChanged

protected void setChanged()
Mark the object as having changed it's state. hasChanged() returns true after execution

See Also:
hasChanged()