}
return "" + separator;
}
+
+ /**
+ * Converts a list to a string with a delimiter before each term except the
+ * first. Returns an empty string given a null or zero-length argument. This
+ * can be replaced with StringJoiner in Java 8.
+ *
+ * @param terms
+ * @param delim
+ * @return
+ */
+ public static String listToDelimitedString(List<String> terms,
+ String delim)
+ {
+ StringBuilder sb = new StringBuilder(32);
+ if (terms != null && !terms.isEmpty())
+ {
+ boolean appended = false;
+ for (String term : terms)
+ {
+ if (appended)
+ {
+ sb.append(delim);
+ }
+ appended = true;
+ sb.append(term);
+ }
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Convenience method to parse a string to an integer, returning 0 if the
+ * input is null or not a valid integer
+ *
+ * @param s
+ * @return
+ */
+ public static int parseInt(String s)
+ {
+ int result = 0;
+ if (s != null && s.length() > 0)
+ {
+ try
+ {
+ result = Integer.parseInt(s);
+ } catch (NumberFormatException ex)
+ {
+ }
+ }
+ return result;
+ }
}