Commit b88167dd authored by Matt Tucker's avatar Matt Tucker Committed by matt

Added better null and empty handling.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3941 b35dd754-fafc-0310-a699-88a17e54d16e
parent 804c3d9d
......@@ -898,10 +898,13 @@ public class StringUtils {
*
* @return a String representing the Collection.
*/
public static String collectionToString(Collection<String> list) {
public static String collectionToString(Collection<String> collection) {
if (collection == null || collection.isEmpty()) {
return "";
}
StringBuilder buf = new StringBuilder();
String delim = "";
for (String element : list) {
for (String element : collection) {
buf.append(delim);
buf.append(element);
delim = ",";
......@@ -915,12 +918,13 @@ public class StringUtils {
* @return a Collection representing the String.
*/
public static Collection<String> stringToCollection(String string) {
if (string == null || string.trim().length() == 0) {
return Collections.emptyList();
}
Collection<String> collection = new ArrayList<String>();
if (string != null) {
StringTokenizer tokens = new StringTokenizer(string, ",");
while (tokens.hasMoreTokens()) {
collection.add(tokens.nextToken().trim());
}
StringTokenizer tokens = new StringTokenizer(string, ",");
while (tokens.hasMoreTokens()) {
collection.add(tokens.nextToken().trim());
}
return collection;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment