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 int
myId
The id of this objectprotected static int
myIdCounter_
A counter to count the number of created to assign "unique" idsprotected 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
-
Constructor Summary
Constructors Constructor Description DataObservable()
DataObservable(java.lang.String name)
-
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 observableboolean
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 attachedint
countObservers()
Returns how many observers are currently observing the observablevoid
deleteObserver(ObserverIfc observer)
Allows the deletion (removing) of an observer from the observablevoid
deleteObservers()
Deletes all the observers from the observableint
getId()
Returns the id for this data sourcejava.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 techniqueint
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 changedouble
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 nameprotected void
setObserverState(int observerState)
protected void
setValue(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:
getName
in 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:
getId
in 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:
getValue
in 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:
getPreviousValue
in 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:ObservableIfc
Allows the adding (attaching) of an observer to the observable- Specified by:
addObserver
in interfaceObservableIfc
- 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 interfaceObservableIfc
- 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 interfaceObservableIfc
-
contains
public final boolean contains(ObserverIfc observer)
Description copied from interface:ObservableIfc
Returns true if the observer is already attached- Specified by:
contains
in interfaceObservableIfc
- 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 interfaceObservableIfc
- Returns:
- number of observers
-
notifyObservers
protected final void notifyObservers(java.lang.Object theObserved, java.lang.Object arg)
-
-