private static <T> CharSequence commaSeparate(CsvValueEscaper<T> escaper, T... values) { StringBuilder sb = new StringBuilder(values.length * VALUE_LENGTH_ESTIMATE); if (values.length > 0) { int end = values.length - 1; for (int i = 0; i < end; i++) { sb.append(escaper.escape(values[i])).append(COMMA); } sb.append(escaper.escape(values[end])); } return sb; }
private static <T> CharSequence commaSeparate( CsvValueEscaper<T> escaper, Iterable<? extends T> values) { @SuppressWarnings("rawtypes") final StringBuilder sb = values instanceof Collection ? new StringBuilder(((Collection) values).size() * VALUE_LENGTH_ESTIMATE) : new StringBuilder(); Iterator<? extends T> iterator = values.iterator(); if (iterator.hasNext()) { T next = iterator.next(); while (iterator.hasNext()) { sb.append(escaper.escape(next)).append(COMMA); next = iterator.next(); } sb.append(escaper.escape(next)); } return sb; }