1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.utgenome.gwt.utgb.client.util;
26
27 import java.util.ArrayList;
28 import java.util.List;
29
30
31
32
33
34
35
36 public class StringUtil {
37
38
39
40
41 private StringUtil() {
42 }
43
44
45
46
47
48
49
50
51
52
53 public static String join(String[] elementList, String separator) {
54 StringBuffer b = new StringBuffer();
55 for (int i = 0; i < elementList.length - 1; i++) {
56 b.append(elementList[i]);
57 b.append(separator);
58 }
59 b.append(elementList[elementList.length - 1]);
60 return b.toString();
61 }
62
63 public static String join(List<String> elementList, String separator) {
64 if (elementList.isEmpty())
65 return "";
66 StringBuffer b = new StringBuffer();
67 for (int i = 0; i < elementList.size() - 1; i++) {
68 b.append(elementList.get(i));
69 b.append(separator);
70 }
71 b.append(elementList.get(elementList.size() - 1));
72 return b.toString();
73 }
74
75 public static String joinIterable(Iterable<String> element, String separator) {
76 List<String> list = new ArrayList<String>();
77 for (String each : element) {
78 list.add(each);
79 }
80 return join(list, separator);
81 }
82
83
84
85
86
87
88 public static String joinWithWS(String[] elementList) {
89 return join(elementList, " ");
90 }
91
92 public static String unquote(String s) {
93 if (s.startsWith("\"") && s.endsWith("\""))
94 return s.substring(1, s.length() - 1);
95 else
96 return s;
97 }
98
99
100
101
102
103
104
105 public static int toInt(String sInt) {
106 if (sInt == null)
107 throw new NullPointerException();
108 String intWithoutComma = sInt.replaceAll("[ ,]", "");
109 return Integer.parseInt(intWithoutComma);
110 }
111
112
113
114
115
116
117
118 public static String formatNumber(int number) {
119 StringBuilder s = new StringBuilder();
120 String intValue = Integer.toString(number);
121
122 final int len = intValue.length();
123 for (int i = 0; i < len; ++i) {
124 s.append(intValue.charAt(i));
125
126 int digit = len - i - 1;
127 if (digit != 0 && (digit % 3 == 0)) {
128 s.append(',');
129 }
130 }
131 return s.toString();
132 }
133
134 }