juneau-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clr-apache <...@git.apache.org>
Subject [GitHub] incubator-juneau pull request #2: related to JUNEAU-49 and its inclusion via...
Date Tue, 30 May 2017 01:30:31 GMT
Github user clr-apache commented on a diff in the pull request:

    https://github.com/apache/incubator-juneau/pull/2#discussion_r118998959
  
    --- Diff: juneau-core/src/main/java/org/apache/juneau/internal/StringUtils.java ---
    @@ -618,7 +618,9 @@ public static boolean isEmpty(String s) {
     	 * @return <jk>true</jk> if specified string is <jk>null</jk>
or it's {@link #toString()} method returns an empty string.
     	 */
     	public static boolean isEmpty(Object s) {
    -		return s == null || s.toString().isEmpty();
    +		if( s == null ) return true;
    +		if( s instanceof List ) return ((List) s).size() == 0;
    --- End diff --
    
    There is a big discussion on stackoverflow on this topic. 
    https://stackoverflow.com/questions/3321526/should-i-use-string-isempty-or-equalsstring
    I like the simple 
    "".equals(s)
    which handles the null case.
    
    If you include s being an instance of collection, it seems that you could use
    if (s instanceof Iterable) return (Iterable) s).isEmpty();
    Then even user-defined types that implement Iterable can be used.
    



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message