stella.parameter
Class StopWatch

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by stella.parameter.AbstractParameter
                  extended by stella.parameter.AbstractValue
                      extended by stella.parameter.StopWatch
All Implemented Interfaces:
Cloneable, Parameter, StatePreserving, ParameterDepending, Value, ExitCleaning, Initializable, LocalizedSupplying, Preserving, PropertySupplying, Reloadable, ResourceSupplying
Direct Known Subclasses:
AlarmWatch, CountDownWatch, RollOverWatch

public class StopWatch
extends AbstractValue
implements ParameterDepending, StatePreserving, Reloadable

A stop watch parameter counts elapsed time. The value it returns is always a long, giving the totally elapsed time in ms. A stop watch can be halted for an unlimited time with the stop() method. After a call to start() it starts accumulating time again. To reset the time counter to zero, call reset() which is an abreviation to setValue(java.lang.Number) with a zero Long.


Nested Class Summary
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private  Long acttime
          The value of the stop watch at the last stop() call.
private static long DEFINIT
          The default initial time of the stop watch.
private static String DEFTIME
          The default name of the time to use.
static String KEY_INIT
          The key linked to a start value of the stop watch.
static String KEY_TIME
          The key linked to the name of the time to use.
private  long starttime
          The long recording the time at a {link #start} call.
private  Value timer
          The parameter denoting time.
 
Fields inherited from class stella.parameter.AbstractParameter
KEY_FORMAT, KEY_NAME, KEY_PRESERVE, UNKNOWN
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Constructor Summary
StopWatch(Map prop)
          Constructs a new stop watch.
 
Method Summary
 String getFormatted()
          Formats the output to show seconds instead of milliseconds.
private  long getTime()
          Returns the current time.
 Number getValue()
          Gets the current value of the stop watch.
 boolean isCounting()
          Returns true if the stop watch is currently running.
 boolean preserve()
          Preserves the overall true time of the trigger.
 void registerParameter(Parameter time)
          Registers the time parameter to this trigger.
 double rescanned(String key, String old, String newval)
          It is not possible to rescan the time parameter name.
 void reset()
          Resets the counter of the stop watch.
 void restart()
          Resets the counter of the stop watch and starts it, if not already running.
 boolean restore()
          Initializes the trigger.
 Number setValue(Number newval)
          Sets the value of the stop watch.
 void start()
          Stats the stop watch.
 void stop()
          Stops the stop watch.
 
Methods inherited from class stella.parameter.AbstractValue
get, set
 
Methods inherited from class stella.parameter.AbstractParameter
createParameter, delivers, exit, getFormatted, getName, getPreserveFile, getString, getString, init, register, setName, toString
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, setObject, setProperties, setProperty, stringProperties
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface stella.Parameter
get, getName, getString, set
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 
Methods inherited from interface util.Initializable
init
 
Methods inherited from interface util.ExitCleaning
exit
 
Methods inherited from interface util.Reloadable
reload
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 

Field Detail

KEY_INIT

public static final String KEY_INIT
The key linked to a start value of the stop watch.

See Also:
Constant Field Values

KEY_TIME

public static final String KEY_TIME
The key linked to the name of the time to use.

See Also:
Constant Field Values

DEFINIT

private static final long DEFINIT
The default initial time of the stop watch.

See Also:
Constant Field Values

DEFTIME

private static final String DEFTIME
The default name of the time to use.

See Also:
Constant Field Values

timer

private Value timer
The parameter denoting time. If null the system clock is used.


acttime

private Long acttime
The value of the stop watch at the last stop() call.


starttime

private long starttime
The long recording the time at a {link #start} call.

Constructor Detail

StopWatch

public StopWatch(Map prop)
Constructs a new stop watch. If no initial time is given in the properties, this stop watch will start accumulation from DEFINIT. Accumulation will only start after a call to start()

Method Detail

rescanned

public double rescanned(String key,
                        String old,
                        String newval)
It is not possible to rescan the time parameter name. All other return 1.

Specified by:
rescanned in interface Reloadable
Overrides:
rescanned in class AbstractParameter

setValue

public Number setValue(Number newval)
Sets the value of the stop watch. If called while counting, the actual value of the stop watch increases according to the difference between the old and the new value.

Specified by:
setValue in interface Value

getValue

public Number getValue()
Gets the current value of the stop watch. If the starttime is zero, acttime is returned. Otherwise - the stop watch is running - the value of acttime plus the difference between the current time and the starttime is returned.

Specified by:
getValue in interface Value

registerParameter

public void registerParameter(Parameter time)
Registers the time parameter to this trigger. If none is found, the system clock is used.

Specified by:
registerParameter in interface ParameterDepending

restore

public boolean restore()
Initializes the trigger. When the super method is called, the initial state of this trigger is set. Accordingly, we start counting if we are true.

Specified by:
restore in interface Preserving
Returns:
False, if restoring the value was not possible.

preserve

public boolean preserve()
Preserves the overall true time of the trigger.

Specified by:
preserve in interface Preserving
Returns:
false, if preserving the current state was not possible

start

public void start()
Stats the stop watch. A call to this method is ignored if the stop watch is already running. Otherwise, the starttime is set to the current time.


stop

public void stop()
Stops the stop watch. If the stop watch was running, the time elapsed since the last valid call to start() is added to the actual time. To signal that the stop watch has stopped, the starttime is set to zero.


reset

public void reset()
Resets the counter of the stop watch. This method forks to setValue(java.lang.Number) with a zero-valued Long. The running/stoped state of the watch is inaffected.


restart

public void restart()
Resets the counter of the stop watch and starts it, if not already running.


isCounting

public boolean isCounting()
Returns true if the stop watch is currently running.


getFormatted

public String getFormatted()
Formats the output to show seconds instead of milliseconds.

Specified by:
getFormatted in interface Parameter
Overrides:
getFormatted in class AbstractParameter

getTime

private long getTime()
Returns the current time. If the timer parameter has been set, this time is used, otherwise the system time is grabbed.