@Test public void testJoinNonEmpty() { assertEquals("Separate this character", Tools.joinNonEmpty(new String[]{"", "Separate", "this", null, "character", "", null}, ' ')); assertEquals("", Tools.joinNonEmpty(new String[]{}, 'x')); assertEquals(" Tools.joinNonEmpty(new String[]{" assertEquals(" Tools.joinNonEmpty(new String[]{null, " assertEquals(" Tools.joinNonEmpty(new String[]{"/", "", "/", null}, '/')); assertEquals("/,2", Tools.joinNonEmpty(new String[]{"/", " ", "2", null}, ',')); }
public static String joinNonEmpty(String[] array, char separator) { boolean somethingAdded = false; StringBuilder sb = new StringBuilder(); for (String str : array) { if (StringUtils.hasText(str)) { if (!somethingAdded) { somethingAdded = true; } else { sb.append(separator); } sb.append(str); } } return sb.toString(); }
Tools { public static String joinNonEmpty(String[] array, char separator) { boolean somethingAdded = false; StringBuilder sb = new StringBuilder(); for (String str : array) { if (StringUtils.hasText(str)) { if (!somethingAdded) { somethingAdded = true; } else { sb.append(separator); } sb.append(str); } } return sb.toString(); } }
Tools { public static String joinNonEmpty(String[] array, char separator) { boolean somethingAdded = false; StringBuilder sb = new StringBuilder(); for (String str : array) { if (StringUtils.hasText(str)) { if (!somethingAdded) { somethingAdded = true; } else { sb.append(separator); } sb.append(str); } } return sb.toString(); } private  Tools(); }
Tools { public static String joinNonEmpty(String[] array, char separator) { boolean somethingAdded = false; StringBuilder sb = new StringBuilder(); for (String str : array) { if (StringUtils.hasText(str)) { if (!somethingAdded) { somethingAdded = true; } else { sb.append(separator); } sb.append(str); } } return sb.toString(); } private  Tools(); static String toString(Object value); static String joinNonEmpty(String[] array, char separator); static String marshalToXml(Object obj, Class sourceClass); @SuppressWarnings("unchecked") static String marshalToXml(T obj, QName qName); @SuppressWarnings("unchecked") static T unmarshalFromXml(String xml, Class<T> targetClass); static DateTime toUTC(DateTime localDateTime); static DateTime fromUTC(DateTime utcTime); static DateTime fromUTC(long utcMillis); }
Tools { public static String joinNonEmpty(String[] array, char separator) { boolean somethingAdded = false; StringBuilder sb = new StringBuilder(); for (String str : array) { if (StringUtils.hasText(str)) { if (!somethingAdded) { somethingAdded = true; } else { sb.append(separator); } sb.append(str); } } return sb.toString(); } private  Tools(); static String toString(Object value); static String joinNonEmpty(String[] array, char separator); static String marshalToXml(Object obj, Class sourceClass); @SuppressWarnings("unchecked") static String marshalToXml(T obj, QName qName); @SuppressWarnings("unchecked") static T unmarshalFromXml(String xml, Class<T> targetClass); static DateTime toUTC(DateTime localDateTime); static DateTime fromUTC(DateTime utcTime); static DateTime fromUTC(long utcMillis);  }