1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
* The contents of this file are subject to the Mozilla Public License Version
5
* 1.1 (the "License"); you may not use this file except in compliance with
6
* the License. You may obtain a copy of the License at
7
* http://www.mozilla.org/MPL/
9
* Software distributed under the License is distributed on an "AS IS" basis,
10
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
* for the specific language governing rights and limitations under the
14
* The Original Code is the reusable ccl java library
15
* (http://www.kclee.com/clemens/java/ccl/).
17
* The Initial Developer of the Original Code is
19
* Portions created by Chr. Clemens Lee are Copyright (C) 2002
20
* Chr. Clemens Lee. All Rights Reserved.
22
* Contributor(s): Chr. Clemens Lee <clemens@kclee.com>
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the MPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the MPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
38
package net.sourceforge.cobertura.javancss;
40
import java.util.Vector;
43
* A general purpose class with a variety of support and convenience methods.
45
* <p> There are different groups of methods in this class:
47
* <br><a href="#print(char)">print methods</a> - convenience methods for System.out.print etc. that additionally make sure output is gets flushed immediately.
48
* <br><a href="#isEmpty(java.lang.String)">string methods</a>
49
* <br><a href="#concat(java.util.Vector)">string/vector converter methods</a>
50
* <br><a href="#getConstantObject()">miscellaneous methods</a>
53
* Some basic but none the less the most used methods by myself are:<br>
54
* - {@link #isEmpty(java.lang.String) isEmpty}<br>
55
* - {@link #stringToLines(java.lang.String) stringToLines}<br>
56
* - {@link #sleep(int) sleep}<br>
59
* @author <a href="http://www.kclee.com/clemens/">
60
* Chr. Clemens Lee</a>
61
* <<a href="mailto:clemens@kclee.com">
68
public static final Object CONSTANT_OBJECT = new Object();
71
* This is an utility class, there is (should be) no need
72
* for an instance of this class.
79
// -----------------------------------------------------
80
// debug methods and assertion stuff
81
// -----------------------------------------------------
84
* panicIf <=> not assert. Throws ApplicationException if true.
85
* It's not necessary to catch this exception.
87
static void panicIf(boolean bPanic_)
91
throw (new RuntimeException());
96
* panicIf <=> not assert. Throws ApplicationException if true.
97
* It's not necessary to catch this exception.
99
* @param sMessage_ The error message for the Exception.
101
static void panicIf(boolean bPanic_, String sMessage_)
105
throw (new RuntimeException(sMessage_));
110
* Tests, if a given String equals null or "".
112
public static boolean isEmpty(String sTest_)
114
if (sTest_ == null || sTest_.equals(""))
123
* This function takes a String and separates it into different
124
* lines. The last line does not need to have a separator character.
126
* @param lines_ The number of lines that should be extracted.
127
* Zero if maximum number of lines is requested.
128
* @param cCutter_ The character that separates pString_ into
131
* @return The single lines do not contain the cCutter_
132
* character at the end.
134
private static Vector stringToLines(int lines_, String pString_, char cCutter_)
136
int maxLines = Integer.MAX_VALUE;
142
Vector vRetVal = new Vector();
143
if (pString_ == null)
149
for (; maxLines > 0; maxLines--)
151
int endIndex = pString_.indexOf(cCutter_, startIndex);
154
if (startIndex < pString_.length())
156
endIndex = pString_.length();
163
String sLine = pString_.substring(startIndex, endIndex);
164
vRetVal.addElement(sLine);
165
startIndex = endIndex + 1;
172
* This function takes a String and separates it into different
173
* lines. The last line does not need to have a separator character.
175
* @param cCutter_ The character that separates pString_ into
178
* @return The single lines do not contain the cCutter_ character
181
private static Vector stringToLines(String pString_, char cCutter_)
183
return stringToLines(0, pString_, cCutter_);
187
* This function takes a String and separates it into different
188
* lines. The last line does not need to have a '\n'. The function
189
* can't handle dos carriage returns.
191
* @return The single lines do not contain the '\n' character
194
public static Vector stringToLines(String pString_)
196
return stringToLines(pString_, '\n');
200
* Current thread sleeps in seconds.
202
private static void sleep(int seconds_)
206
Thread.sleep(seconds_ * 1000);
208
catch (Exception pException)