View Javadoc

1   /*
2    *
3    * Copyright 2008 Commsen International
4    * 
5    * Licensed under the Common Public License, Version 1.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    *      http://www.opensource.org/licenses/cpl1.0.txt
10   * 
11   * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
12   * EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS 
13   * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
14   *
15   */
16  package com.commsen.stopwatch;
17  
18  /***
19   * Simple class to wrap basic stopwatch methods. The only reason this class exists is to make happy
20   * those developers who prefer
21   * 
22   * <code>
23   * <pre>
24   * .....
25   * Meter meter = Stopwatch.startMeter(&quot;group&quot;, &quot;label&quot;);
26   * // some code to be measured
27   * meter.stop();
28   * ...
29   * </pre>
30   *</code>
31   * 
32   * over
33   * 
34   * <code>
35   * <pre>
36   * .....
37   * long swId = Stopwatch.start(&quot;group&quot;, &quot;label&quot;);
38   * // some code to be measured
39   * Stopwatch.stop(swId);
40   * ...
41   * </pre>
42   *</code>
43   * 
44   * although it does exactly the same thing.
45   * 
46   * @author Milen Dyankov
47   * @since 0.4
48   */
49  public class Meter {
50  
51  	private final long id;
52  
53  
54  	/***
55  	 * Creates new object wrapping the id returned by {@link Stopwatch#start(String, String)};
56  	 * 
57  	 * @param id the stopwatch id
58  	 */
59  	Meter(long id) {
60  		this.id = id;
61  	}
62  
63  
64  	/***
65  	 * Simply forwards to {@link Stopwatch#stop(long)}
66  	 */
67  	public void stop() {
68  		Stopwatch.stop(id);
69  	}
70  
71  
72  	/***
73  	 * Simply forwards to {@link Stopwatch#skip(long)}
74  	 */
75  	public void cancel() {
76  		Stopwatch.skip(id);
77  	}
78  
79  }