Class Stopwatch


  • @ParametersAreNonnullByDefault
    public final class Stopwatch
    extends Object
    An object that measures elapsed time using Instant.
    • Method Detail

      • createUnstarted

        @Nonnull
        public static Stopwatch createUnstarted()
        Creates (but does not start) a new stopwatch.
        Returns:
        a new stopwatch
      • createStarted

        @Nonnull
        public static Stopwatch createStarted()
        Creates (and starts) a new stopwatch.
        Returns:
        a new stopwatch
      • isRunning

        public boolean isRunning()
        Checks whether this stopwatch is currently running.
        Returns:
        true if start() has been called, and stop() has been not called since the last call to start()
      • start

        @Nonnull
        public Stopwatch start()
        Starts this stopwatch.
        Returns:
        this stopwatch
        Throws:
        IllegalStateException - if this stopwatch is already running
      • stop

        @Nonnull
        public Stopwatch stop()
        Stops this stopwatch.
        Returns:
        this stopwatch
        Throws:
        IllegalStateException - if this stopwatch is already stopped
      • reset

        @Nonnull
        public Stopwatch reset()
        Sets the elapsed time for this stopwatch to 0, and places it in a stopped state.
        Returns:
        this stopwatch
      • elapsed

        @Nonnull
        public Duration elapsed()
        Returns the current elapsed time shown on this stopwatch. If this stopwatch is currently running, the duration is processed according to the starting point until now.
        Returns:
        the duration