1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.composite.util;
17
18 import java.lang.reflect.Array;
19 import java.util.Collection;
20
21 /***
22 * @author Matt Sgarlata
23 * @since Mar 11, 2005
24 */
25 public class StringUtils {
26
27 public static String capitalize(String string) {
28 return
29 string.substring(0, 1).toUpperCase() +
30 string.substring(1, string.length());
31 }
32
33 public static String join(Object values, String separator) {
34 if (values == null) {
35 return null;
36 }
37 else if (values instanceof Collection) {
38 Collection valuesCollection = (Collection) values;
39 return join(
40 valuesCollection.toArray(new Object[valuesCollection.size()]),
41 separator);
42 }
43 else if (values.getClass().isArray()) {
44 StringBuffer buffer = new StringBuffer();
45 int length = Array.getLength(values);
46 for (int i = 0; i < length; i++) {
47 buffer.append(Array.get(values, i));
48 if (i < length - 1) {
49 buffer.append(separator);
50 }
51 }
52 return buffer.toString();
53 }
54 else {
55 throw new IllegalArgumentException("Cannot join objects of class '" + values.getClass().getName() + "'");
56 }
57 }
58
59 }