forked from phoedos/pmd
Optimized lpad, thanks to Radim Kubacki for the code!
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4930 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -284,9 +284,9 @@ public class Benchmark {
|
||||
while (buf2.length() <= 50) {
|
||||
buf2.append(" ");
|
||||
}
|
||||
buf2.append(StringUtil.lpad(MessageFormat.format("{0,number,0.00000}", new Object[]{new Double(benchmarkResult.getTime()/1000000000.0)}), 8, " "));
|
||||
buf2.append(StringUtil.lpad(MessageFormat.format("{0,number,0.00000}", new Object[]{new Double(benchmarkResult.getTime()/1000000000.0)}), 8));
|
||||
if (benchmarkResult.getType() <= TYPE_RULE_CHAIN_RULE) {
|
||||
buf2.append(StringUtil.lpad(MessageFormat.format("{0,number,###,###,###,###,###}", new Object[]{new Long(benchmarkResult.getCount())}), 20, " "));
|
||||
buf2.append(StringUtil.lpad(MessageFormat.format("{0,number,###,###,###,###,###}", new Object[]{new Long(benchmarkResult.getCount())}), 20));
|
||||
}
|
||||
switch (benchmarkResult.getType()) {
|
||||
case TYPE_RULE:
|
||||
|
@ -263,19 +263,15 @@ public class StringUtil {
|
||||
* Left pads a string.
|
||||
* @param s The String to pad
|
||||
* @param length The desired minimum length of the resulting padded String
|
||||
* @param pad The String to pad with
|
||||
* @return The resulting left padded String
|
||||
*/
|
||||
public static String lpad(String s, int length, String pad) {
|
||||
if (pad == null || pad.length() == 0) {
|
||||
pad = " ";
|
||||
}
|
||||
StringBuffer buf = new StringBuffer(length);
|
||||
for (int i = 0; i < length - s.length();) {
|
||||
buf.append(pad);
|
||||
i+= pad.length();
|
||||
}
|
||||
buf.append(s);
|
||||
return buf.toString();
|
||||
public static String lpad(String s, int length) {
|
||||
String res = s;
|
||||
if (length - s.length() > 0) {
|
||||
char [] arr = new char[length - s.length()];
|
||||
java.util.Arrays.fill(arr, ' ');
|
||||
res = new StringBuffer(length).append(arr).append(s).toString();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user