01: /**
02: * $Revision$
03: * $Date$
04: *
05: * Copyright (C) 2006-2007 Jive Software. All rights reserved.
06: *
07: * This software is published under the terms of the GNU Public License (GPL),
08: * a copy of which is included in this distribution.
09: */package org.jivesoftware.openfire.gateway.util;
10:
11: import java.util.List;
12:
13: /**
14: * A simple class to perform various string related functions.
15: *
16: * @author Daniel Henninger
17: */
18: public class StringUtils {
19:
20: /**
21: * Convenience routine to perform a string join for groups in the database.
22: * @param array Array of strings to join together.
23: * @param delim Delimiter to separate strings with.
24: * @return Joined string
25: */
26: public static String join(List<String> array, String delim) {
27: StringBuffer sb = join(array, delim, new StringBuffer());
28: return sb.toString();
29: }
30:
31: /**
32: * Helper function for primary use join function.
33: * @param array Array of strings to join together.
34: * @param delim Delimiter to separate strings with.
35: * @param sb String buffer instance to work from.
36: * @return String buffer instance.
37: */
38: static StringBuffer join(List<String> array, String delim,
39: StringBuffer sb) {
40: Boolean first = true;
41: for (String s : array) {
42: if (!first) {
43: sb.append(delim);
44: } else {
45: first = false;
46: }
47: sb.append(s);
48: }
49: return sb;
50: }
51:
52: }
|