01: /*
02: * Copyright 2005 by Lars Torunski
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: *
16: */
17: package com.torunski.crawler.util;
18:
19: /**
20: * A stop watch for milliseconds.
21: *
22: * @author Lars Torunski
23: * @version $Revision: 1.3 $
24: */
25: public final class StopWatch {
26:
27: /** the total time in milliseconds */
28: private long total;
29:
30: /** the start time in milliseconds */
31: private long start;
32:
33: /**
34: * Starts the stop watch.
35: */
36: public void start() {
37: start = System.currentTimeMillis();
38: }
39:
40: /**
41: * Stops the stop watch.
42: * @return the millis between the last start and current stop of this watch.
43: */
44: public long stop() {
45: long diff = System.currentTimeMillis() - start;
46: total += diff;
47: return diff;
48: }
49:
50: /**
51: * Resets the stop watch to 0.
52: */
53: public void reset() {
54: total = 0;
55: }
56:
57: /**
58: * @return returns the stopped total time in milliseconds.
59: */
60: public long getTime() {
61: return total;
62: }
63:
64: }
|