KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > krysalis > jcharts > test > StopWatch


1
2 /***********************************************************************************************
3  * File Info: $Id: StopWatch.java,v 1.1 2003/05/17 17:01:14 nathaniel_auvil Exp $
4  * Copyright (C) 2000
5  * Author: Nathaniel G. Auvil
6  * Contributor(s):
7  *
8  * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
9  *
10  * Redistribution and use of this software and associated documentation ("Software"), with or
11  * without modification, are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain copyright statements and notices.
14  * Redistributions must also contain a copy of this document.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
17  * conditions and the following disclaimer in the documentation and/or other materials
18  * provided with the distribution.
19  *
20  * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to endorse or promote
21  * products derived from this Software without prior written permission of Nathaniel G.
22  * Auvil. For written permission, please contact nathaniel_auvil@users.sourceforge.net
23  *
24  * 4. Products derived from this Software may not be called "jCharts" nor may "jCharts" appear
25  * in their names without prior written permission of Nathaniel G. Auvil. jCharts is a
26  * registered trademark of Nathaniel G. Auvil.
27  *
28  * 5. Due credit should be given to the jCharts Project (http://jcharts.sourceforge.net/).
29  *
30  * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS ``AS IS'' AND ANY
31  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
32  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
33  * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
38  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
39  ************************************************************************************************/

40
41 package org.krysalis.jcharts.test;
42
43
44
45 public class StopWatch
46 {
47     private long start;
48     private long stop;
49
50
51     public StopWatch()
52     {
53
54     }
55
56
57     public void start()
58     {
59         this.start= System.currentTimeMillis();
60     }
61
62
63
64     public void stop()
65     {
66         this.stop= System.currentTimeMillis();
67     }
68
69
70
71     public String JavaDoc toString()
72     {
73         long difference= this.stop - this.start;
74         long seconds= ( difference / 1000 ) % 60;
75         long minutes= difference / 1000 / 60 % 60;
76         long hours= difference / 1000 / 60 / 60;
77
78         StringBuffer JavaDoc s= new StringBuffer JavaDoc( 100 );
79         s.append( "Total Execution Time: " + hours + "h " + minutes + "m " + seconds + "s." );
80         return s.toString();
81     }
82
83
84
85 }
86
Popular Tags