Class Stopwatch
java.lang.Object
org.apache.jackrabbit.oak.commons.time.Stopwatch
-
Method Summary
Modifier and TypeMethodDescriptionstatic Stopwatchstatic StopwatchcreateStarted(Clock clock) static StopwatchcreateStarted(Supplier<Long> ticker) static Stopwatchstatic StopwatchcreateUnstarted(Supplier<Long> ticker) elapsed()Gets elapsed time asDuration.longGets elapsed time using the suppliedTimeUnit.booleanreset()Resets the stop watch, and puts it into stopped state.start()Starts the stop watch, will fail when running.stop()Stops the stop watch, will fail when not running.toString()
-
Method Details
-
createStarted
- Returns:
- a running stop watch, using
System.nanoTime().
-
createStarted
- Returns:
- a running stop watch, using the supplied supplier.
-
createStarted
- Returns:
- a running stop watch, using the supplied clock.
Note that only
Clock.millis()will be used, thus the watch will have ms precision at most.
-
createUnstarted
- Returns:
- a non-running stop watch, using the supplied supplier.
-
createUnstarted
- Returns:
- a non-running stop watch, using
System.nanoTime().
-
start
Starts the stop watch, will fail when running.- Returns:
- the stop watch
-
stop
Stops the stop watch, will fail when not running.- Returns:
- the stop watch
-
reset
Resets the stop watch, and puts it into stopped state.- Returns:
- the stop watch
-
isRunning
public boolean isRunning()- Returns:
- whether the stop watch is running
-
elapsed
Gets elapsed time using the suppliedTimeUnit.- Parameters:
timeunit- time unit- Returns:
- elapsed time in the specified unit
-
elapsed
Gets elapsed time asDuration.- Returns:
- elapsed time
-
toString
-