Mikhail2048 commented on pull request #857: URL: https://github.com/apache/commons-lang/pull/857#issuecomment-1049547423
> > > Hello @Mikhail2048 & @ecki The new method name does not match its internal test, one or the other needs fixing. Since the method works on any Object, not a String, it likely belongs next to `ObjectUtils.toString(Object, Supplier<String>)`. Please adjust this PR. > > > > > > I think it is not entirely true. We cannot test any given object for emptiness, so, if we have `ObjectUtils.toString(Object, Supplier<String>)`, then I do not understand how should we test passed object for emptiness. We can, of course, test if passed object is `null` and then apply `Supplier`, but empty string and null string are not the same. > > I think the appropriate solution would look like this: in general is a great idea to implement something like `ObjectUtils.applyIfNull(T, Supplier<T>)`, but I think we should left `StringUtils.defaultIfEmpty(final T source, final Supplier<T> default)`, maybe with slightly different name, for example `StringUtils.applyIfNull(final T source, final Supplier<T> default)` > > We have ObjectUtils#isEmpty() but we could have a String specific version I suppose... Well, yes, but if we should have a String specific version of isEmpty(), then I think we really need to think twice on why we are placing this in ObjectUtils class. It is, from my opinion, a bit controversial - we are placing `String` specific logic into ObjectUtils. I think that the best solution would be - to create general purpose utility method in `ObjectUtils`, like `ObjectUtils#defaultIfNull(T object, Supplier<T> supplier)`, but specifically for strings we can have `StringUtils#defaultIfEmpty(String object, Supplier<String> supplier)` - because logic of how we verify emptiness of String/CharSequence is different from any other object. @garydgregory I think it will be a great solution, is not it?) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
