Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide Joiner as Collector #3951

Open
bjmi opened this issue Jul 3, 2020 · 1 comment
Open

Provide Joiner as Collector #3951

bjmi opened this issue Jul 3, 2020 · 1 comment

Comments

@bjmi
Copy link

bjmi commented Jul 3, 2020

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>"));
@Saucistophe
Copy link
Contributor

There, I added a basic implementation.
Not for the Android flavor, since it does not support Java 8 interfaces (if I read #5269 well).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants