guava
guava copied to clipboard
Provide Joiner as Collector
The main advantage of Guava Joiner over JDKs Collectors.joining(...) or StringJoiner that it can handle arbitrary objects and has a convenient builder api to express e.g. .useForNull(nullText).
Thus allow the usage of Joiner when streams come into play and get rid of cumbersome expressions like .filter(Objects::nonNull).map(Object::toString).
E.g. with factory method joiningOn(...):
objectStream.collect(joiningOn(", ").skipNulls());
objectStream.collect(joiningOn(", ").useForNull("<N/A>"));
Alternatively Joiner could implement Collector interface.
objectStream.collect(Joiner.on(", ").skipNulls());
objectStream.collect(Joiner.on(", ").useForNull("<N/A>"));
There, I added a basic implementation. Not for the Android flavor, since it does not support Java 8 interfaces (if I read #5269 well).