Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_903+3D / applications / appgvSIG / src / com / vividsolutions / jump / util / DebugTimer.java @ 10722

History | View | Annotate | Download (2.47 KB)

1 312 fernando
2
/*
3
 * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
4
 * for visualizing and manipulating spatial features with geometry and attributes.
5
 *
6
 * Copyright (C) 2003 Vivid Solutions
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
 *
22
 * For more information, contact:
23
 *
24
 * Vivid Solutions
25
 * Suite #1A
26
 * 2328 Government Street
27
 * Victoria BC  V8T 5G5
28
 * Canada
29
 *
30
 * (250)385-6040
31
 * www.vividsolutions.com
32
 */
33
34
package com.vividsolutions.jump.util;
35
36
import com.vividsolutions.jts.util.Stopwatch;
37
38
39
public class DebugTimer {
40
    private static final int TIME_LEN = 10;
41
    private static DebugTimer timer = new DebugTimer();
42
    private Stopwatch sw = null;
43
    private String blankStr;
44
45
    public DebugTimer() {
46
        sw = new Stopwatch();
47
        sw.start();
48
        blankStr = fillString(TIME_LEN, ' ');
49
    }
50
51
    public static void startStatic(String msg) {
52
        timer.start(msg);
53
    }
54
55
    public static void logEventStatic(String msg) {
56
        timer.logEvent(msg);
57
    }
58
59
    public void start(String msg) {
60
        System.out.println("Started    " + msg);
61
        sw.start();
62
    }
63
64
    public void logEvent(String msg) {
65
        String elapsedStr = formatTime(sw.getTimeString());
66
        System.out.println("Elapsed: " + elapsedStr + "    " + msg);
67
        sw.start();
68
    }
69
70
    public String formatTime(String timeStr) {
71
        if (timeStr.length() < TIME_LEN) {
72
            String filled = blankStr + timeStr;
73
            int start = filled.length() - TIME_LEN;
74
75
            return filled.substring(start);
76
        }
77
78
        // don't pad if it's already longer
79
        return timeStr;
80
    }
81
82
    public String fillString(int len, char ch) {
83
        StringBuffer buf = new StringBuffer(len);
84
85
        for (int i = 0; i < len; i++) {
86
            buf.append(ch);
87
        }
88
89
        return buf.toString();
90
    }
91
}