filebot/source/net/sourceforge/tuned/StringUtilities.java

53 lines
1019 B
Java
Raw Normal View History

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