Package ej.observable

Class SimpleObservable

  • Direct Known Subclasses:
    KernelSimpleObservable

    public class SimpleObservable
    extends Object
    This class represents an observable variant which can handle only a single observer.
    • Constructor Detail

      • SimpleObservable

        public SimpleObservable()
        Creates a simple observable.
    • 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 null if 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 is null.
      • 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. The hasChanged() method will now return true.
      • 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 the hasChanged() method will now return false. This method is called automatically by the notifyObserver() method.
      • hasChanged

        public boolean hasChanged()
        Gets whether or not this simple observable has changed.
        Returns:
        true if and only if the setChanged() method has been called more recently than the clearChanged() method on this simple observable, false otherwise.
      • notifyObserver

        public void notifyObserver()
        Notifies the registered observer, if any.