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

Lang-1345 Enhance non-empty strings #278

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

ThrawnCA
Copy link

No description provided.

@coveralls
Copy link

coveralls commented Jul 17, 2017

Coverage Status

Coverage decreased (-0.2%) to 94.9% when pulling 3ec23f1 on ThrawnCA:LANG-1345-enhance-non-empty-strings into f692351 on apache:master.

Copy link
Member

@garydgregory garydgregory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really do not like the method names starting with "extend". It does not smell right to me. We have some methods here that start with "default", maybe that's better.

@stokito
Copy link

stokito commented Jun 23, 2018

For me is not clear importance of the new methods. I can't remember situations when I needed for something like this. And even if I need something like this I'll write the function myself and I'll not even think about to search something in Commons Lang library. Time spent to looking for the method will be ten time more then write myself.
Maybe commons lang itself uses the function internally then it can make sense.

It would be great if you can give us an examples of usage and how they are important.

@ThrawnCA
Copy link
Author

ThrawnCA commented Jun 24, 2018

A typical case would be that you're assembling a sentence, and if a component is not empty, you need to add a space beforehand. (Sometimes join will handle this, but other times it's not the right tool for the situation.)

Or you're building a URL, and if there's a non-blank query string, you need to put a question mark before it.

Really, any situation where part of a string is optional but requires special formatting if present.

@garydgregory The trouble with "default" names is that this functionality is the opposite. The defaultXXX methods have the logic, "if present, leave untouched; otherwise use the second parameter." This would instead be, "if present, apply the second parameter; otherwise, leave untouched." Could use "appendIfNotXXX" and "prependIfNotXXX" I suppose, but I'd rather combine prefixes and suffixes in one method.

@aaabramov
Copy link
Contributor

Could use "appendIfNotXXX" and "prependIfNotXXX" I suppose, but I'd rather combine prefixes and suffixes in one method.

I think this naming would be better and more granular.

@ThrawnCA
Copy link
Author

ThrawnCA commented Nov 1, 2018

And I've come across another situation where I want this: assembling a filename from customer name parts, and adding a separator for middle name if (and only if) it's provided.

- Also fix up documentation to match other functions
Copy link
Contributor

@RahulNagekar RahulNagekar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@ThrawnCA
Copy link
Author

Bump. I believe I've addressed the changes that were requested.

@ThrawnCA
Copy link
Author

Just came across another use case for this. One of our systems is retrieving customer email addresses, if provided, and decorating them with the customer's name, eg John Smith <john.smith@example.com>. If there is no email address, then it should return an empty string, rather than John Smith <>.

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