Class Stopwatch

java.lang.Object
Stopwatch

public class Stopwatch extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a Stopwatch
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    lap()
    laps the stopwatch
    if the stopwatch is not running, this is equivalent to start()
    int
    reads the value of this stopwatch
    int
    read(int lap)
    reads the specific value of a lap on this stopwatch
    lap numbers start from 0
    int
    read(int lap, boolean totalTime)
    reads the specific value of a lap on this stopwatch
    lap numbers start from 0
    static String
    readable(long milliseconds)
    converts the time in milliseconds to a human-readable string
    void
    resets the stopwatch
    equivalent to writing (variable) = new Stopwatch();
    int
    starts the stopwatch
    int
    stops the stopwatch
    can be restarted with "start()"
    if stopwatch is not running, this is equivalent to reset()
    void
    wait(int ms)
    waits for a set time

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Stopwatch

      public Stopwatch()
      Constructs a Stopwatch
  • Method Details

    • start

      public int start()
      starts the stopwatch
      Returns:
      the time it took to start the stopwatch, typically very small
    • stop

      public int stop()
      stops the stopwatch
      can be restarted with "start()"
      if stopwatch is not running, this is equivalent to reset()
      Returns:
      equivalent to read()
    • lap

      public int lap()
      laps the stopwatch
      if the stopwatch is not running, this is equivalent to start()
      Returns:
      equivalent to read()
    • read

      public int read()
      reads the value of this stopwatch
      Returns:
      value of this stopwatch
    • read

      public int read(int lap)
      reads the specific value of a lap on this stopwatch
      lap numbers start from 0
      Parameters:
      lap - the lap number
      Returns:
      the length of this lap
      equivalent to read(lap, false)
    • read

      public int read(int lap, boolean totalTime)
      reads the specific value of a lap on this stopwatch
      lap numbers start from 0
      Parameters:
      lap - the lap number
      totalTime - whether or not to count the total time since start()(true) or to count lap-to-lap(false)
      Returns:
      the length of this lap
    • reset

      public void reset()
      resets the stopwatch
      equivalent to writing (variable) = new Stopwatch();
    • wait

      public void wait(int ms)
      waits for a set time
      Parameters:
      ms - the time to wait in ms
    • readable

      public static String readable(long milliseconds)
      converts the time in milliseconds to a human-readable string
      Parameters:
      milliseconds - the number of milliseconds to convert
      Returns:
      human-readable string