garydgregory opened a new pull request, #1244: URL: https://github.com/apache/commons-lang/pull/1244
Refactor string joining into AppendableJoiner Joins an array or Iterable into an existing Appendable like a StringBuilder, aiming for call sites to avoid creating intermediary Strings. This is like `String.join(CharSequence, CharSequence)`, `String.join(CharSequence, Iterable)`, and `StringJoiner`. Keep an instance in a (static) variable for efficient joining into an `Appendable` or `StringBuilder` without creating temporary Strings. Use the builder and instance methods to reuse the same joining prefix, suffix, delimiter, and string conversion. For example: ```java // A reuseable instance private static final AppendableJoiner<Object> JOINER = AppendableJoiner.builder() .setPrefix("[") .setSuffix("]") .setDelimiter(", ") .get(); ... // Builds straight into a StringBuilder: StringBuilder sbuilder = new StringBuilder("1"); JOINER.join(sbuilder, "A", "B"); sbuilder.append("2"); JOINER.join(sbuilder, "C", "D"); sbuilder.append("3"); // Returns "1[A, B]2[C, D]3" return sbuilder.toString(); ``` To provide a custom `Object` element to `CharSequence` converter, call Builder.setElementAppender(FailableBiConsumer), for example: ```java private static final AppendableJoiner<Item> JOINER = AppendableJoiner.builder() .setElementAppender(e -> (a, e) -> a.append(e.getFoo()) a.append(e.getBar()) a.append('!')) ... .get(); ``` This class is immutable and thread-safe. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@commons.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org