1 package net.logAnalyzer.utils;
2
3 /***
4 * A simple toolkit to manipulate Strings.
5 *
6 * @author Karim REFEYTON
7 * @version 1.0
8 */
9 public class StringUtils {
10
11 /***
12 * Creation forbidden...
13 */
14 private StringUtils() {
15 super();
16 }
17
18 /***
19 * Right format a value using the specified filler. If the value is greater
20 * than length, the value is returned unchanged.
21 *
22 * @param value
23 * Value to format.
24 * @param length
25 * Resulting length.
26 * @param filler
27 * Filler to use.
28 * @return Formatted value or unchanged if greater than the specified
29 * length.
30 */
31
32 public static String formatRight(long value, int length, char filler) {
33 return formatRight(Long.toString(value), length, filler);
34 }
35
36 /***
37 * Right format a value using the specified filler. If the value is greater
38 * than length, the value is returned unchanged.
39 *
40 * @param value
41 * Value to format.
42 * @param length
43 * Resulting length.
44 * @param filler
45 * Filler to use.
46 * @return Formatted value or unchanged if greater than the specified
47 * length.
48 */
49
50 public static String formatRight(String value, int length, char filler) {
51 if (value.length() >= length) {
52 return value;
53 } else {
54 StringBuffer result = new StringBuffer();
55 for (int i = 0; i < length; i++) {
56 result.append(filler);
57 }
58 if (value == null || value.equals("")) {
59 return value;
60 } else {
61 result.append(value);
62 return result.substring(result.length() - length);
63 }
64 }
65 }
66 }