Package ej.observable
Class SimpleObservable
- java.lang.Object
-
- ej.observable.SimpleObservable
-
- Direct Known Subclasses:
KernelSimpleObservable
public class SimpleObservable extends Object
This class represents an observable variant which can handle only a single observer.
-
-
Constructor Summary
Constructors Constructor Description SimpleObservable()Creates a simple observable.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidclearChanged()Indicates that this simple observable has no longer changed, or that it has already notified all of its observers of its most recent change, so that thehasChanged()method will now returnfalse.ObservergetObserver()Returns the observer of this simple observable, if it is set.booleanhasChanged()Gets whether or not this simple observable has changed.voidnotifyObserver()Notifies the registered observer, if any.protected voidsetChanged()Marks this simple observable as having been changed.voidsetObserver(Observer observer)Sets the observer of this simple observable.voidunsetObserver()Unsets the observer of this simple observable.voidunsetObserver(Observer observer)Unsets the observer of this simple observable if it the same instance as the given observer.
-
-
-
Method Detail
-
getObserver
@Nullable public Observer getObserver()
Returns the observer of this simple observable, if it is set.- Returns:
- the observer of this simple observable, or
nullif it is not set.
-
setObserver
public void setObserver(Observer observer)
Sets the observer of this simple observable.- Parameters:
observer- the observer to set.- Throws:
NullPointerException- if the given observer isnull.
-
unsetObserver
public void unsetObserver(Observer observer)
Unsets the observer of this simple observable if it the same instance as the given observer.- Parameters:
observer- the observer to unset.
-
unsetObserver
public void unsetObserver()
Unsets the observer of this simple observable.
-
setChanged
protected void setChanged()
Marks this simple observable as having been changed. ThehasChanged()method will now returntrue.
-
clearChanged
protected void clearChanged()
Indicates that this simple observable has no longer changed, or that it has already notified all of its observers of its most recent change, so that thehasChanged()method will now returnfalse. This method is called automatically by thenotifyObserver()method.
-
hasChanged
public boolean hasChanged()
Gets whether or not this simple observable has changed.- Returns:
trueif and only if thesetChanged()method has been called more recently than theclearChanged()method on this simple observable,falseotherwise.
-
notifyObserver
public void notifyObserver()
Notifies the registered observer, if any.
-
-