01: /*
02: * Copyright 2003 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package velosurf.util;
18:
19: import java.util.Iterator;
20: import java.util.Collection;
21: import java.util.List;
22: import java.util.ArrayList;
23: import java.util.TreeMap;
24:
25: /** This static class gathers utilities for lists of strings.
26: *
27: * @author <a href=mailto:claude.brisson@gmail.com>Claude Brisson</a>
28: */
29: public class StringLists {
30: /** builds an array list initially filled with <code>size</code> dummy objects.
31: *
32: * @param size size of the list
33: * @return the new ArrayList
34: */
35: public static List<String> getPopulatedArrayList(int size) {
36: List<String> list = new ArrayList<String>(size);
37: String s = new String();
38: for (int i = 0; i < size; i++)
39: list.add(s);
40: return list;
41: }
42:
43: /** joins strings using a separator.
44: *
45: * @param stringList strings to join
46: * @param joinString separator to include between strings
47: * @return the result of the join
48: */
49: public static String join(Collection stringList, String joinString) {
50: Iterator i = stringList.iterator();
51:
52: StringBuffer result = new StringBuffer();
53:
54: if (!i.hasNext())
55: return "";
56:
57: result.append(i.next().toString());
58:
59: while (i.hasNext()) {
60: result.append(joinString);
61: result.append(i.next().toString());
62: }
63: return result.toString();
64: }
65: }
|