Class Stopwatch
- java.lang.Object
-
- org.apache.jackrabbit.oak.commons.time.Stopwatch
-
public final class Stopwatch extends Object
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StopwatchcreateStarted()static StopwatchcreateStarted(Clock clock)static StopwatchcreateStarted(Supplier<Long> ticker)static StopwatchcreateUnstarted()static StopwatchcreateUnstarted(Supplier<Long> ticker)Durationelapsed()Gets elapsed time asDuration.longelapsed(TimeUnit timeunit)Gets elapsed time using the suppliedTimeUnit.booleanisRunning()Stopwatchreset()Resets the stop watch, and puts it into stopped state.Stopwatchstart()Starts the stop watch, will fail when running.Stopwatchstop()Stops the stop watch, will fail when not running.StringtoString()
-
-
-
Method Detail
-
createStarted
public static Stopwatch createStarted()
- Returns:
- a running stop watch, using
System.nanoTime().
-
createStarted
public static Stopwatch createStarted(Supplier<Long> ticker)
- Returns:
- a running stop watch, using the supplied supplier.
-
createStarted
public static Stopwatch createStarted(Clock clock)
- 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
public static Stopwatch createUnstarted(Supplier<Long> ticker)
- Returns:
- a non-running stop watch, using the supplied supplier.
-
createUnstarted
public static Stopwatch createUnstarted()
- Returns:
- a non-running stop watch, using
System.nanoTime().
-
start
public Stopwatch start()
Starts the stop watch, will fail when running.- Returns:
- the stop watch
-
stop
public Stopwatch stop()
Stops the stop watch, will fail when not running.- Returns:
- the stop watch
-
reset
public Stopwatch 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
public long elapsed(TimeUnit timeunit)
Gets elapsed time using the suppliedTimeUnit.- Parameters:
timeunit- time unit- Returns:
- elapsed time in the specified unit
-
-