kucci / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Joiner should provide useForBlank and skipBlanks #450

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Sometimes we use blank/empty strings instead of nulls, and we may want to skip 
them or replace them with something when joining.

Basically, for the same reason that Joiner provides useForNull and skipNulls, 
it should also provide useForBlank and skipBlanks.

Original issue reported on code.google.com by yogy.nam...@gmail.com on 16 Oct 2010 at 1:26

GoogleCodeExporter commented 9 years ago
Perhaps we want the empty string check to be done on the result of the 
toString() on each part object, and not directly on the parts themselves. In 
this sense the two methods are different from useForNull and skipNulls, which 
does the null check only on the part directly, and would append "null" if the 
toString of a non-null object returns null.

If this is too radical, then just check for empty string on the part directly.

Original comment by yogy.nam...@gmail.com on 16 Oct 2010 at 2:37

GoogleCodeExporter commented 9 years ago
This seems like a case where the feature wouldn't be generally useful enough to 
justify its existence, especially given that Joiner isn't just for use on lists 
of Stings and that toString() methods for objects that aren't CharSequences 
probably shouldn't be returning empty or blank (in my opinion).

What I'd probably do is make a Predicate "notBlank()" and/or a Function 
"useForBlank(String)" and use filtering or transforming to achieve the same 
result:

  String skippedBlanks = Joiner.on(',').join(Iterables.filter(strings, StringPredicates.notBlank()));
  String replacedBlanks = Joiner.on(',').join(Iterables.transform(strings, StringFunctions.useForBlank("none")));

Original comment by cgdec...@gmail.com on 16 Oct 2010 at 4:19

GoogleCodeExporter commented 9 years ago
I agree with Colin.  Thanks for the suggestion, Yogy.

Original comment by kevinb@google.com on 16 Oct 2010 at 5:28

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09