Class Stopwatch

  • All Implemented Interfaces:
    java.time.temporal.TemporalAmount

    public class Stopwatch
    extends java.lang.Object
    implements java.time.temporal.TemporalAmount
    A tool for measuring time, mainly for log messages. Note this class isn't affected by the mock clock of TimeUtils.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.time.temporal.Temporal addTo​(java.time.temporal.Temporal temporal)  
      java.time.Duration elapsed()
      Gets the elapsed time on the watch.
      long get​(java.time.temporal.TemporalUnit temporalUnit)  
      java.util.List<java.time.temporal.TemporalUnit> getUnits()  
      boolean isRunning()
      Returns true if the stopwatch is running.
      static Stopwatch start()
      Start a newly created stopwatch.
      Stopwatch stop()
      Stops the stopwatch, if it is running.
      java.time.temporal.Temporal subtractFrom​(java.time.temporal.Temporal temporal)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • start

        public static Stopwatch start()
        Start a newly created stopwatch.
        Returns:
        the stopwatch that was just started
      • stop

        public Stopwatch stop()
        Stops the stopwatch, if it is running.
        Returns:
        the stopwatch that is stopped
      • isRunning

        public boolean isRunning()
        Returns true if the stopwatch is running.
        Returns:
        true if the stopwatch is running, false otherwise
      • elapsed

        public java.time.Duration elapsed()
        Gets the elapsed time on the watch. This doesn't stop the watch.
        Returns:
        elapsed time
      • get

        public long get​(java.time.temporal.TemporalUnit temporalUnit)
        Specified by:
        get in interface java.time.temporal.TemporalAmount
      • getUnits

        public java.util.List<java.time.temporal.TemporalUnit> getUnits()
        Specified by:
        getUnits in interface java.time.temporal.TemporalAmount
      • addTo

        public java.time.temporal.Temporal addTo​(java.time.temporal.Temporal temporal)
        Specified by:
        addTo in interface java.time.temporal.TemporalAmount
      • subtractFrom

        public java.time.temporal.Temporal subtractFrom​(java.time.temporal.Temporal temporal)
        Specified by:
        subtractFrom in interface java.time.temporal.TemporalAmount
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object