-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
base: master
Are you sure you want to change the base?
Lang-1345 Enhance non-empty strings #278
Conversation
There was a problem hiding this 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.
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. It would be great if you can give us an examples of usage and how they are important. |
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 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. |
I think this naming would be better and more granular. |
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
…LANG-1345-enhance-non-empty-strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
- Adjust punctuation and phrasing to match other functions - Fix some of the example cases to properly reflect behavior
Bump. I believe I've addressed the changes that were requested. |
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 |
No description provided.