blob: 6314023fe303fdb66b538f179710fbc80812edb9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/* ____ ____ ____ ____ ______ *\
** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
** /_____/\____/\___/\____/____/ **
\* */
// $Id$
package scala.tools.util;
import java.util.ArrayList;
/**
* This abstract class implements the collection of timings. How the
* collected timings are issued has to be implemented in subclasses.
*/
public abstract class AbstractTimer implements Timer {
//########################################################################
// Private Fields
/** A stack for maintaining start times */
private final ArrayList starts = new ArrayList();
//########################################################################
// Public Methods
/** Issues a timing information (duration in milliseconds). */
public abstract void issue(String message, long duration);
/** Starts a new timer. */
public void start() {
starts.add(new Long(System.currentTimeMillis()));
}
/** Ends the current timer. */
public void stop(String message) {
long stop = System.currentTimeMillis();
long start = ((Long)starts.remove(starts.size() - 1)).longValue();
issue(message, stop - start);
}
/** Drops the current timer. */
public void drop() {
starts.remove(starts.size() - 1);
}
//########################################################################
}
|