-
public class StopWatchA simple stopwatch to keep a correct and updated record of the running duration of processes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceStopWatch.TickListener
-
Field Summary
Fields Modifier and Type Field Description protected volatile booleanisRunningprotected inttickDelayprotected floatspeedMultiplier
-
Method Summary
Modifier and Type Method Description voidstart()Starts the stopwatch. voidstop()Stops the stopwatch, capturing the ending time voidreset()Resets the current time for the stopWatch voidoverrideCurrentTime(long time)Forcefully sets the current time for the stopwatch. longgetTime()Retrieves the current time for the stopwatch. intgetTimeInt()Retrieves the current time for the stopwatch. voidsetTickListener(StopWatch.TickListener listener)Sets the listener to be notified for each time update (tick) booleanisRunning()Determines if the stopwatch is currently running intgetTickDelay()Retrieves the approximate duration between time updates. floatgetSpeedMultiplier()Retrieves the current multiplier used for the current time calculations. voidsetTickDelay(int milliSeconds)Sets the approximate duration between time updates. voidsetSpeedMultiplier(float multiplier)Sets the multiplier to use when calculating the passed duration. -
-
Constructor Detail
-
StopWatch
StopWatch()
-
StopWatch
StopWatch(boolean processOnStartingThread)
- Parameters:
processOnStartingThread- True if the repeating process should be handled on the same thread that created the Repeater
-
StopWatch
StopWatch(Handler handler)
- Parameters:
handler- The Handler to use for the repeating process
-
-
Method Detail
-
start
void start()
Starts the stopwatch. This will continue from where we last left off,if you need to start from 0 call reset first.
-
stop
void stop()
Stops the stopwatch, capturing the ending time
-
reset
void reset()
Resets the current time for the stopWatch
-
overrideCurrentTime
void overrideCurrentTime(long time)
Forcefully sets the current time for the stopwatch.
- Parameters:
time- The new stopwatch time in milliseconds
-
getTime
long getTime()
Retrieves the current time for the stopwatch. If the stopwatch is stopped then theending time will be returned.
-
getTimeInt
int getTimeInt()
Retrieves the current time for the stopwatch. If the stopwatch is stopped then theending time will be returned.
-
setTickListener
void setTickListener(StopWatch.TickListener listener)
Sets the listener to be notified for each time update (tick)
- Parameters:
listener- The listener or null
-
isRunning
boolean isRunning()
Determines if the stopwatch is currently running
-
getTickDelay
int getTickDelay()
Retrieves the approximate duration between time updates.
-
getSpeedMultiplier
float getSpeedMultiplier()
Retrieves the current multiplier used for the current time calculations.NOTE: the default is 1
-
setTickDelay
void setTickDelay(int milliSeconds)
Sets the approximate duration between time updates.
- Parameters:
milliSeconds- The approximate duration between time updates [default: {@value #DEFAULT_TICK_DELAY}]
-
setSpeedMultiplier
void setSpeedMultiplier(float multiplier)
Sets the multiplier to use when calculating the passed duration. Thiswon't affect the tick delay setTickDelay but will changethe output for the current time.
- Parameters:
multiplier- The amount to multiply the duration between each tick by
-
-
-
-