1
2
3
4
5
6
7 package com.diasparsoftware.gsbase;
8
9 /***
10 * An production-quality implementation of
11 * com.gargoylesoftware.base.util.Stopwatch
12 * that uses the system clock.
13 *
14 * @version $Revision: 1.1 $
15 * @author <a href="mailto:jbr@diasparsoftware.com">J. B. Rainsberger</a>
16 */
17 public class SystemClockStopwatch implements Stopwatch {
18 private boolean started = false;
19 private long startTime = -1;
20
21 private boolean stopped;
22 private long stopTime = -1;
23
24 public void start() {
25 startTime = System.currentTimeMillis();
26 started = true;
27 }
28
29 public void stop() {
30 stopped = true;
31 stopTime = System.currentTimeMillis();
32 }
33
34 public void reset() {
35 started = false;
36 stopped = false;
37 }
38
39 public long getLastTime() {
40 if (started && stopped) {
41 return stopTime - startTime;
42 }
43 else {
44 return 0;
45 }
46 }
47 }