package org.svetovid.util;

public class Stopwatch {

    private long startTime;
    private long pauseTime;
    private long pauseLength;
    private int timesPaused;

    public Stopwatch() {
        this(true);
    }

    public Stopwatch(boolean autoStart) {
        startTime = System.currentTimeMillis();
        pauseTime = startTime;
        pauseLength = 0;
        timesPaused = 0;
        if (!autoStart) {
            timesPaused++;
        }
    }

    public void pause() {
        if (timesPaused == 0) {
            pauseTime = System.currentTimeMillis();
        }
        timesPaused++;
    }

    public void resume() {
        if (timesPaused > 0) {
            timesPaused--;
            if (timesPaused == 0) {
                pauseLength = pauseLength + (System.currentTimeMillis() - pauseTime);
            }
        }
    }

    public boolean isPaused() {
        return timesPaused > 0;
    }

    public double time() {
        long now = isPaused() ? pauseTime : System.currentTimeMillis();
        long time = now - startTime - pauseLength;
        return time / 1000.0;
    }
}

@@ -23,16 +23,71 @@
 til;%0D%0A%0D%0A
+import java.util.ArrayList;%0D%0Aimport java.util.List;%0D%0A%0D%0A
 public c
@@ -160,24 +160,51 @@
 pauseTime;%0D%0A
+    private long lapTime;%0D%0A
     private 
@@ -238,23 +238,107 @@
 ate 
-int timesPaused
+long lapPauseLength;%0D%0A    private int timesPaused;%0D%0A    private List%3CLong%3E laps = new ArrayList%3C%3E()
 ;%0D%0A%0D
@@ -518,33 +518,92 @@
 tTime;%0D%0A        
-p
+lapTime = startTime;%0D%0A        pauseLength = 0;%0D%0A        lapP
 auseLength = 0;%0D
@@ -1069,24 +1069,117 @@
 auseTime);%0D%0A
+                lapPauseLength = lapPauseLength + (System.currentTimeMillis() - pauseTime);%0D%0A
             
@@ -1466,12 +1466,816 @@
 %0D%0A    %7D%0D
+%0A%0D%0A    public double lap() %7B%0D%0A        long now = isPaused() ? pauseTime : System.currentTimeMillis();%0D%0A        long time = now - lapTime - lapPauseLength;%0D%0A        lapTime = now;%0D%0A        lapPauseLength = 0;%0D%0A        laps.add(time);%0D%0A        return time / 1000.0;%0D%0A    %7D%0D%0A%0D%0A    public double%5B%5D getLapTimes() %7B%0D%0A        int n = laps.size();%0D%0A        double%5B%5D result = new double%5Bn%5D;%0D%0A        for (int i = 0; i %3C n; i++) %7B%0D%0A            result%5Bi%5D = laps.get(i) / 1000.0;%0D%0A        %7D%0D%0A        return result;%0D%0A    %7D%0D%0A%0D%0A    public double%5B%5D getTotalTimes() %7B%0D%0A        int n = laps.size();%0D%0A        long sum = 0;%0D%0A        double%5B%5D result = new double%5Bn%5D;%0D%0A        for (int i = 0; i %3C n; i++) %7B%0D%0A            sum = sum + laps.get(i);%0D%0A            result%5Bi%5D = sum / 1000.0;%0D%0A        %7D%0D%0A        return result;%0D%0A    %7D%0D
 %0A%7D%0D%0A

Add lap measurement to Stopwatch class