Package jsl.utilities
Class DataObservable
- java.lang.Object
-
- jsl.utilities.DataObservable
-
- All Implemented Interfaces:
ObservableIfc,GetNameIfc,GetValueIfc,IdentityIfc,PreviousValueIfc
- Direct Known Subclasses:
IterativeDataObservable
public abstract class DataObservable extends java.lang.Object implements ObservableIfc, GetValueIfc, PreviousValueIfc, IdentityIfc
-
-
Field Summary
Fields Modifier and Type Field Description protected intmyIdThe id of this objectprotected static intmyIdCounter_A counter to count the number of created to assign "unique" idsprotected java.lang.StringmyNameHolds the name of the statistic for reporting purposes.static intNEW_VALUEAn "enum" to indicate that a new value has just been made available to observers
-
Constructor Summary
Constructors Constructor Description DataObservable()DataObservable(java.lang.String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddObserver(ObserverIfc observer)Allows the adding (attaching) of an observer to the observablebooleancheckObserverState(int observerState)Checks to see if the technique is in the given observer state.booleancontains(ObserverIfc observer)Returns true if the observer is already attachedintcountObservers()Returns how many observers are currently observing the observablevoiddeleteObserver(ObserverIfc observer)Allows the deletion (removing) of an observer from the observablevoiddeleteObservers()Deletes all the observers from the observableintgetId()Returns the id for this data sourcejava.lang.StringgetName()Gets the name.intgetObserverState()Returns an integer representing the state of the technique This can be used by Observers to find out what occurred for the techniqueintgetPreviousObserverState()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 changedoublegetPreviousValue()Returns the previous value for this data source if there was one returns Double.NaN if no previous value is available.doublegetValue()Every data source must implement the getValue method.protected voidnotifyObservers(int observerState)Used to notify observers that this data source has entered the given state.protected voidnotifyObservers(java.lang.Object theObserved, java.lang.Object arg)protected voidsetId()voidsetName(java.lang.String str)Sets the nameprotected voidsetObserverState(int observerState)protected voidsetValue(double value)Properly assigns the value and remembers previous value notifies any observers of the change
-
-
-
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.
-
-
Method Detail
-
getName
public final java.lang.String getName()
Gets the name.- Specified by:
getNamein interfaceGetNameIfc- 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:
getIdin interfaceIdentityIfc- 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:
getValuein interfaceGetValueIfc- 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:
getPreviousValuein interfacePreviousValueIfc- 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:ObservableIfcAllows the adding (attaching) of an observer to the observable- Specified by:
addObserverin interfaceObservableIfc- Parameters:
observer- the observer to attach
-
deleteObserver
public final void deleteObserver(ObserverIfc observer)
Description copied from interface:ObservableIfcAllows the deletion (removing) of an observer from the observable- Specified by:
deleteObserverin interfaceObservableIfc- Parameters:
observer- the observer to delete
-
deleteObservers
public final void deleteObservers()
Description copied from interface:ObservableIfcDeletes all the observers from the observable- Specified by:
deleteObserversin interfaceObservableIfc
-
contains
public final boolean contains(ObserverIfc observer)
Description copied from interface:ObservableIfcReturns true if the observer is already attached- Specified by:
containsin interfaceObservableIfc- Parameters:
observer- the observer to check- Returns:
- true if attached
-
countObservers
public final int countObservers()
Description copied from interface:ObservableIfcReturns how many observers are currently observing the observable- Specified by:
countObserversin interfaceObservableIfc- Returns:
- number of observers
-
notifyObservers
protected final void notifyObservers(java.lang.Object theObserved, java.lang.Object arg)
-
-