Package jsl.utilities

Class DataObservable

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int myId
      The id of this object
      protected static int myIdCounter_
      A counter to count the number of created to assign "unique" ids
      protected java.lang.String myName
      Holds the name of the statistic for reporting purposes.
      static int NEW_VALUE
      An "enum" to indicate that a new value has just been made available to observers
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addObserver​(ObserverIfc observer)
      Allows the adding (attaching) of an observer to the observable
      boolean checkObserverState​(int observerState)
      Checks to see if the technique is in the given observer state.
      boolean contains​(ObserverIfc observer)
      Returns true if the observer is already attached
      int countObservers()
      Returns how many observers are currently observing the observable
      void deleteObserver​(ObserverIfc observer)
      Allows the deletion (removing) of an observer from the observable
      void deleteObservers()
      Deletes all the observers from the observable
      int getId()
      Returns the id for this data source
      java.lang.String getName()
      Gets the name.
      int getObserverState()
      Returns an integer representing the state of the technique This can be used by Observers to find out what occurred for the technique
      int getPreviousObserverState()
      Returns an integer representing the previous state of the DataSource This can be used by Observers to find out which action occurred prior to the current state change
      double getPreviousValue()
      Returns the previous value for this data source if there was one returns Double.NaN if no previous value is available.
      double getValue()
      Every data source must implement the getValue method.
      protected void notifyObservers​(int observerState)
      Used to notify observers that this data source has entered the given state.
      protected void notifyObservers​(java.lang.Object theObserved, java.lang.Object arg)  
      protected void setId()  
      void setName​(java.lang.String str)
      Sets the name
      protected void setObserverState​(int observerState)  
      protected void setValue​(double value)
      Properly assigns the value and remembers previous value notifies any observers of the change
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • myIdCounter_

        protected static int myIdCounter_
        A counter to count the number of created to assign "unique" ids
      • NEW_VALUE

        public static final int NEW_VALUE
        An "enum" to indicate that a new value has just been made available to observers
      • myId

        protected int myId
        The id of this object
      • myName

        protected java.lang.String myName
        Holds the name of the statistic for reporting purposes.
    • Constructor Detail

      • DataObservable

        public DataObservable()
      • DataObservable

        public DataObservable​(java.lang.String name)
    • Method Detail

      • getName

        public final java.lang.String getName()
        Gets the name.
        Specified by:
        getName in interface GetNameIfc
        Returns:
        The name of object.
      • setName

        public final void setName​(java.lang.String str)
        Sets the name
        Parameters:
        str - The name as a string.
      • getId

        public final int getId()
        Returns the id for this data source
        Specified by:
        getId in interface IdentityIfc
        Returns:
      • getValue

        public double getValue()
        Every data source must implement the getValue method. This method simply returns the current value. Returns Double.NaN if no current value is available
        Specified by:
        getValue in interface GetValueIfc
        Returns:
        The value.
      • getPreviousValue

        public double getPreviousValue()
        Returns the previous value for this data source if there was one returns Double.NaN if no previous value is available.
        Specified by:
        getPreviousValue in interface PreviousValueIfc
        Returns:
      • checkObserverState

        public final boolean checkObserverState​(int observerState)
        Checks to see if the technique is in the given observer state. This method can be used by observers that are interested in reacting to the action associated with this state for the technique. NEW_VALUE
        Returns:
        True means that this DataSource is in the given state.
      • getObserverState

        public final int getObserverState()
        Returns an integer representing the state of the technique This can be used by Observers to find out what occurred for the technique
        Returns:
        The current state
      • getPreviousObserverState

        public final int getPreviousObserverState()
        Returns an integer representing the previous state of the DataSource This can be used by Observers to find out which action occurred prior to the current state change
        Returns:
        The previous state
      • setId

        protected void setId()
      • setValue

        protected void setValue​(double value)
        Properly assigns the value and remembers previous value notifies any observers of the change
        Parameters:
        value -
      • notifyObservers

        protected final void notifyObservers​(int observerState)
        Used to notify observers that this data source has entered the given state. Valid values for observerState include: NEW_VALUE
        Parameters:
        observerState -
      • setObserverState

        protected final void setObserverState​(int observerState)
        Parameters:
        observerState -
      • addObserver

        public final void addObserver​(ObserverIfc observer)
        Description copied from interface: ObservableIfc
        Allows the adding (attaching) of an observer to the observable
        Specified by:
        addObserver in interface ObservableIfc
        Parameters:
        observer - the observer to attach
      • deleteObserver

        public final void deleteObserver​(ObserverIfc observer)
        Description copied from interface: ObservableIfc
        Allows the deletion (removing) of an observer from the observable
        Specified by:
        deleteObserver in interface ObservableIfc
        Parameters:
        observer - the observer to delete
      • deleteObservers

        public final void deleteObservers()
        Description copied from interface: ObservableIfc
        Deletes all the observers from the observable
        Specified by:
        deleteObservers in interface ObservableIfc
      • contains

        public final boolean contains​(ObserverIfc observer)
        Description copied from interface: ObservableIfc
        Returns true if the observer is already attached
        Specified by:
        contains in interface ObservableIfc
        Parameters:
        observer - the observer to check
        Returns:
        true if attached
      • countObservers

        public final int countObservers()
        Description copied from interface: ObservableIfc
        Returns how many observers are currently observing the observable
        Specified by:
        countObservers in interface ObservableIfc
        Returns:
        number of observers
      • notifyObservers

        protected final void notifyObservers​(java.lang.Object theObserved,
                                             java.lang.Object arg)