2009-07-03 12:58:05 +00:00
|
|
|
|
|
|
|
package net.sourceforge.tuned;
|
|
|
|
|
|
|
|
|
2011-11-28 10:24:46 +00:00
|
|
|
import static java.util.Arrays.*;
|
|
|
|
|
2009-07-03 12:58:05 +00:00
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
|
|
|
|
public final class StringUtilities {
|
|
|
|
|
2011-11-28 10:24:46 +00:00
|
|
|
public static boolean isEmptyValue(Object object) {
|
2011-11-29 02:16:49 +00:00
|
|
|
return object == null || object.toString().length() == 0;
|
2011-11-28 10:24:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-29 03:14:39 +00:00
|
|
|
public static String joinBy(CharSequence delimiter, Object... values) {
|
|
|
|
return join(asList(values), delimiter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-03 12:58:05 +00:00
|
|
|
public static String join(Object[] values, CharSequence delimiter) {
|
2011-11-28 10:24:46 +00:00
|
|
|
return join(asList(values), delimiter);
|
2009-07-03 12:58:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-24 20:28:25 +00:00
|
|
|
public static String join(Iterable<?> values, CharSequence delimiter) {
|
2009-07-03 12:58:05 +00:00
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
for (Iterator<?> iterator = values.iterator(); iterator.hasNext();) {
|
2011-11-28 10:24:46 +00:00
|
|
|
Object value = iterator.next();
|
|
|
|
if (!isEmptyValue(value)) {
|
|
|
|
if (sb.length() > 0) {
|
|
|
|
sb.append(delimiter);
|
|
|
|
}
|
|
|
|
|
|
|
|
sb.append(value);
|
2009-07-03 12:58:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dummy constructor to prevent instantiation.
|
|
|
|
*/
|
|
|
|
private StringUtilities() {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|