You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by ThrawnCA <gi...@git.apache.org> on 2017/07/17 23:18:43 UTC

[GitHub] commons-lang pull request #278: Lang-1345 Enhance non-empty strings

GitHub user ThrawnCA opened a pull request:

    https://github.com/apache/commons-lang/pull/278

    Lang-1345 Enhance non-empty strings

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/ThrawnCA/commons-lang LANG-1345-enhance-non-empty-strings

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/commons-lang/pull/278.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #278
    
----
commit fba90c5cd95bc4c75b963382abcc94bed57e4ccd
Author: antuarc <ca...@dsiti.qld.gov.au>
Date:   2017-07-17T23:13:17Z

    [LANG-1345] add methods to extend non-empty and non-blank strings

commit e89ca5ceb5dfbb5e2b94a9f5497c28ecf8c65973
Author: antuarc <ca...@dsiti.qld.gov.au>
Date:   2017-07-17T23:18:00Z

    [LANG-1345] oops fix method name in Javadoc

----


---
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.
---

[GitHub] commons-lang pull request #278: Lang-1345 Enhance non-empty strings

Posted by RahulNagekar <gi...@git.apache.org>.
Github user RahulNagekar commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/278#discussion_r238054600
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -9008,6 +9011,56 @@ public static String appendIfMissingIgnoreCase(final String str, final CharSeque
             return appendIfMissing(str, suffix, true, suffixes);
         }
     
    +    /**
    +     * <p>Returns either the passed in String with the specified suffix attached,
    +     * or if the String is empty ("")/{@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.appendIfNotBlank(null, " ")      = ""
    +     * StringUtils.appendIfNotBlank(null, "-post")  = ""
    +     * StringUtils.appendIfNotBlank("", "-post")    = ""
    +     * StringUtils.appendIfNotBlank(" ", " ")       = "  "
    +     * StringUtils.appendIfNotBlank(" ", "-post")   = " -post"
    +     * StringUtils.appendIfNotBlank("abc", null)    = "abc"
    +     * StringUtils.appendIfNotBlank("abc", "")      = "abc"
    +     * StringUtils.appendIfNotBlank("abc", " ")     = "abc "
    +     * StringUtils.appendIfNotBlank("abc", "-post") = "abc-post"
    +     * </pre>
    +     * @param str the String to check, may be null
    +     * @param suffix  the string to append if 'str' is not empty. Null will be converted to empty string.
    +     * @return the passed in String with suffix added, or empty string
    +     */
    +    public static String appendIfNotEmpty(final String str, final String suffix) {
    +        return isEmpty(str) ? EMPTY : str + defaultString(suffix);
    +    }
    +
    +    /**
    +     * <p>Returns either the passed in String with the specified suffix attached,
    +     * or if the String is whitespace/empty ("")/{@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.appendIfNotBlank(null, " ")      = ""
    --- End diff --
    
    Shouldn't this be returning null instead as the name doesn't say anything about making the original string empty?


---

[GitHub] commons-lang pull request #278: Lang-1345 Enhance non-empty strings

Posted by RahulNagekar <gi...@git.apache.org>.
Github user RahulNagekar commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/278#discussion_r238055373
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -9008,6 +9011,56 @@ public static String appendIfMissingIgnoreCase(final String str, final CharSeque
             return appendIfMissing(str, suffix, true, suffixes);
         }
     
    +    /**
    +     * <p>Returns either the passed in String with the specified suffix attached,
    +     * or if the String is empty ("")/{@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.appendIfNotBlank(null, " ")      = ""
    +     * StringUtils.appendIfNotBlank(null, "-post")  = ""
    +     * StringUtils.appendIfNotBlank("", "-post")    = ""
    +     * StringUtils.appendIfNotBlank(" ", " ")       = "  "
    +     * StringUtils.appendIfNotBlank(" ", "-post")   = " -post"
    +     * StringUtils.appendIfNotBlank("abc", null)    = "abc"
    +     * StringUtils.appendIfNotBlank("abc", "")      = "abc"
    +     * StringUtils.appendIfNotBlank("abc", " ")     = "abc "
    +     * StringUtils.appendIfNotBlank("abc", "-post") = "abc-post"
    +     * </pre>
    +     * @param str the String to check, may be null
    +     * @param suffix  the string to append if 'str' is not empty. Null will be converted to empty string.
    +     * @return the passed in String with suffix added, or empty string
    +     */
    +    public static String appendIfNotEmpty(final String str, final String suffix) {
    +        return isEmpty(str) ? EMPTY : str + defaultString(suffix);
    +    }
    +
    +    /**
    +     * <p>Returns either the passed in String with the specified suffix attached,
    +     * or if the String is whitespace/empty ("")/{@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.appendIfNotBlank(null, " ")      = ""
    +     * StringUtils.appendIfNotBlank(null, "-post")  = ""
    +     * StringUtils.appendIfNotBlank("", "-post")    = ""
    +     * StringUtils.appendIfNotBlank(" ", " ")       = ""
    +     * StringUtils.appendIfNotBlank(" ", "-post")   = ""
    +     * StringUtils.appendIfNotBlank("abc", null)    = "abc"
    +     * StringUtils.appendIfNotBlank("abc", "")      = "abc"
    +     * StringUtils.appendIfNotBlank("abc", " ")     = "abc"
    +     * StringUtils.appendIfNotBlank("abc", "-post") = "abc-post"
    +     * </pre>
    +     * @param str the String to check, may be null
    +     * @param suffix  the string to append if 'str' is not blank. Null will be converted to empty string.
    +     * @return the passed in String with suffix added, or empty string
    +     */
    +    public static String appendIfNotBlank(final String str, final String suffix) {
    +        return isBlank(str) ? EMPTY : str + defaultString(suffix);
    --- End diff --
    
    ```suggestion
            return isBlank(str) ? str : str + defaultString(suffix);
    ```


---

[GitHub] commons-lang pull request #278: Lang-1345 Enhance non-empty strings

Posted by RahulNagekar <gi...@git.apache.org>.
Github user RahulNagekar commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/278#discussion_r238055284
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -9109,6 +9162,56 @@ public static String prependIfMissingIgnoreCase(final String str, final CharSequ
             return prependIfMissing(str, prefix, true, prefixes);
         }
     
    +    /**
    +     * <p>Returns either the passed in String with the specified prefix attached,
    +     * or if the String is whitespace/empty ("")/{@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.prependIfNotEmpty(null, " ")     = ""
    --- End diff --
    
    Shouldn't this be returning null instead as the name doesn't say anything about making the original string empty?


---

[GitHub] commons-lang pull request #278: Lang-1345 Enhance non-empty strings

Posted by RahulNagekar <gi...@git.apache.org>.
Github user RahulNagekar commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/278#discussion_r238055291
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -9109,6 +9162,56 @@ public static String prependIfMissingIgnoreCase(final String str, final CharSequ
             return prependIfMissing(str, prefix, true, prefixes);
         }
     
    +    /**
    +     * <p>Returns either the passed in String with the specified prefix attached,
    +     * or if the String is whitespace/empty ("")/{@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.prependIfNotEmpty(null, " ")     = ""
    +     * StringUtils.prependIfNotEmpty(null, "pre-")  = ""
    +     * StringUtils.prependIfNotEmpty("", "pre-")    = ""
    +     * StringUtils.prependIfNotEmpty(" ", " ")      = "  "
    +     * StringUtils.prependIfNotEmpty(" ", "pre-")   = "pre- "
    +     * StringUtils.prependIfNotEmpty("abc", null)   = "abc"
    +     * StringUtils.prependIfNotEmpty("abc", "")     = "abc"
    +     * StringUtils.prependIfNotEmpty("abc", " ")    = " abc"
    +     * StringUtils.prependIfNotEmpty("abc", "pre-") = "pre-abc"
    +     * </pre>
    +     * @param str the String to check, may be null
    +     * @param prefix  the string to prepend if 'str' is not blank. Null will be converted to empty string.
    +     * @return the passed in String with prefix added, or empty string
    +     */
    +    public static String prependIfNotEmpty(final String str, final String prefix) {
    +        return isEmpty(str) ? EMPTY : defaultString(prefix) + str;
    +    }
    +
    +    /**
    +     * <p>Returns either the passed in String with the specified prefix attached,
    +     * or if the String is whitespace/empty ("")/{@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.prependIfNotBlank(null, " ")     = ""
    --- End diff --
    
    Shouldn't this be returning null instead as the name doesn't say anything about making the original string empty?


---

[GitHub] commons-lang pull request #278: Lang-1345 Enhance non-empty strings

Posted by garydgregory <gi...@git.apache.org>.
Github user garydgregory commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/278#discussion_r161277531
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -7429,6 +7429,55 @@ public static String defaultString(final String str, final String defaultStr) {
             return isEmpty(str) ? defaultStr : str;
         }
     
    +    // Extensions
    +    //-----------------------------------------------------------------------
    +
    +    /**
    +     * <p>Returns either the passed in String with the specified prefix and suffix attached,
    +     * or if the String is whitespace, empty ("") or {@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.extendIfNotBlank(null, "pre-", "-post")  = ""
    +     * StringUtils.extendIfNotBlank("", "pre-", "-post")    = ""
    +     * StringUtils.extendIfNotBlank(" ", "pre-", "-post")   = ""
    +     * StringUtils.extendIfNotBlank("bat", "pre-", "-post") = "pre-bat-bost"
    +     * StringUtils.extendIfNotBlank("bat", null, "-post")      = "bat-post"
    +     * StringUtils.extendIfNotBlank("bat", "pre-", null)      = "pre-bat"
    +     * </pre>
    +     * @param str the String to check, may be null
    +     * @param prefix  the string to prepend if not blank. Null will be converted to empty string.
    +     * @param suffix  the string to append if not blank. Null will be converted to empty string.
    +     * @return the passed in String with prefix and suffix added, or empty string
    +     * @see StringUtils#defaultString(String, String)
    +     */
    +    public static String extendIfNotBlank(final String str, final String prefix, final String suffix) {
    +        return isBlank(str) ? "" : defaultString(prefix) + str + defaultString(suffix);
    +    }
    +
    +    /**
    +     * <p>Returns either the passed in String with the specified prefix and suffix attached,
    +     * or if the String is empty ("") or {@code null}, an empty string.</p>
    +     *
    +     * <pre>
    +     * StringUtils.extendIfNotEmpty(null, "pre-", "-post")  = ""
    +     * StringUtils.extendIfNotEmpty("", "pre-", "-post")    = ""
    +     * StringUtils.extendIfNotEmpty(" ", "pre-", "-post")   = "pre- -post"
    +     * StringUtils.extendIfNotEmpty("bat", "pre-", "-post") = "pre-bat-bost"
    +     * StringUtils.extendIfNotEmpty("bat", null, "-post")      = "bat-post"
    +     * StringUtils.extendIfNotEmpty("bat", "pre-", null)      = "pre-bat"
    +     * </pre>
    +     * @param str the String to check, may be null
    +     * @param prefix  the string to prepend if not empty. Null will be converted to empty string.
    +     * @param suffix  the string to append if not empty. Null will be converted to empty string.
    +     * @return the passed in String with prefix and suffix added, or empty string
    +     * @see StringUtils#defaultString(String, String)
    +     */
    +    public static String extendIfNotEmpty(final String str, final String prefix, final String suffix) {
    +        return isEmpty(str) ? "" : defaultString(prefix) + str + defaultString(suffix);
    --- End diff --
    
    Reuse the EMPTY constant.


---

[GitHub] commons-lang pull request #278: Lang-1345 Enhance non-empty strings

Posted by RahulNagekar <gi...@git.apache.org>.
Github user RahulNagekar commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/278#discussion_r238055393
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -9109,6 +9162,56 @@ public static String prependIfMissingIgnoreCase(final String str, final CharSequ
             return prependIfMissing(str, prefix, true, prefixes);
         }
     
    +    /**
    +     * <p>Returns either the passed in String with the specified prefix attached,
    +     * or if the String is whitespace/empty ("")/{@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.prependIfNotEmpty(null, " ")     = ""
    +     * StringUtils.prependIfNotEmpty(null, "pre-")  = ""
    +     * StringUtils.prependIfNotEmpty("", "pre-")    = ""
    +     * StringUtils.prependIfNotEmpty(" ", " ")      = "  "
    +     * StringUtils.prependIfNotEmpty(" ", "pre-")   = "pre- "
    +     * StringUtils.prependIfNotEmpty("abc", null)   = "abc"
    +     * StringUtils.prependIfNotEmpty("abc", "")     = "abc"
    +     * StringUtils.prependIfNotEmpty("abc", " ")    = " abc"
    +     * StringUtils.prependIfNotEmpty("abc", "pre-") = "pre-abc"
    +     * </pre>
    +     * @param str the String to check, may be null
    +     * @param prefix  the string to prepend if 'str' is not blank. Null will be converted to empty string.
    +     * @return the passed in String with prefix added, or empty string
    +     */
    +    public static String prependIfNotEmpty(final String str, final String prefix) {
    +        return isEmpty(str) ? EMPTY : defaultString(prefix) + str;
    +    }
    +
    +    /**
    +     * <p>Returns either the passed in String with the specified prefix attached,
    +     * or if the String is whitespace/empty ("")/{@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.prependIfNotBlank(null, " ")     = ""
    +     * StringUtils.prependIfNotBlank(null, "pre-")  = ""
    +     * StringUtils.prependIfNotBlank("", "pre-")    = ""
    +     * StringUtils.prependIfNotBlank(" ", " ")      = ""
    +     * StringUtils.prependIfNotBlank(" ", "pre-")   = ""
    +     * StringUtils.prependIfNotBlank("abc", null)   = "abc"
    +     * StringUtils.prependIfNotBlank("abc", "")     = "abc"
    +     * StringUtils.prependIfNotBlank("abc", " ")    = "abc"
    +     * StringUtils.prependIfNotBlank("abc", "pre-") = "pre-abc"
    +     * </pre>
    +     * @param str the String to check, may be null
    +     * @param prefix  the string to prepend if 'str' is not blank. Null will be converted to empty string.
    +     * @return the passed in String with prefix added, or empty string
    +     */
    +    public static String prependIfNotBlank(final String str, final String prefix) {
    +        return isBlank(str) ? EMPTY : defaultString(prefix) + str;
    --- End diff --
    
    ```suggestion
            return isBlank(str) ? str : defaultString(prefix) + str;
    ```


---

[GitHub] commons-lang pull request #278: Lang-1345 Enhance non-empty strings

Posted by RahulNagekar <gi...@git.apache.org>.
Github user RahulNagekar commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/278#discussion_r238078898
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -9008,6 +9011,56 @@ public static String appendIfMissingIgnoreCase(final String str, final CharSeque
             return appendIfMissing(str, suffix, true, suffixes);
         }
     
    +    /**
    +     * <p>Returns either the passed in String with the specified suffix attached,
    +     * or if the String is empty ("")/{@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.appendIfNotBlank(null, " ")      = ""
    +     * StringUtils.appendIfNotBlank(null, "-post")  = ""
    +     * StringUtils.appendIfNotBlank("", "-post")    = ""
    +     * StringUtils.appendIfNotBlank(" ", " ")       = "  "
    +     * StringUtils.appendIfNotBlank(" ", "-post")   = " -post"
    +     * StringUtils.appendIfNotBlank("abc", null)    = "abc"
    +     * StringUtils.appendIfNotBlank("abc", "")      = "abc"
    +     * StringUtils.appendIfNotBlank("abc", " ")     = "abc "
    +     * StringUtils.appendIfNotBlank("abc", "-post") = "abc-post"
    +     * </pre>
    +     * @param str the String to check, may be null
    +     * @param suffix  the string to append if 'str' is not empty. Null will be converted to empty string.
    +     * @return the passed in String with suffix added, or empty string
    +     */
    +    public static String appendIfNotEmpty(final String str, final String suffix) {
    +        return isEmpty(str) ? EMPTY : str + defaultString(suffix);
    +    }
    +
    +    /**
    +     * <p>Returns either the passed in String with the specified suffix attached,
    +     * or if the String is whitespace/empty ("")/{@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.appendIfNotBlank(null, " ")      = ""
    +     * StringUtils.appendIfNotBlank(null, "-post")  = ""
    +     * StringUtils.appendIfNotBlank("", "-post")    = ""
    +     * StringUtils.appendIfNotBlank(" ", " ")       = ""
    +     * StringUtils.appendIfNotBlank(" ", "-post")   = ""
    +     * StringUtils.appendIfNotBlank("abc", null)    = "abc"
    +     * StringUtils.appendIfNotBlank("abc", "")      = "abc"
    +     * StringUtils.appendIfNotBlank("abc", " ")     = "abc"
    --- End diff --
    
    Needs correction
    ```suggestion
         * StringUtils.appendIfNotBlank("abc", " ")     = "abc "
    ```


---

[GitHub] commons-lang pull request #278: Lang-1345 Enhance non-empty strings

Posted by RahulNagekar <gi...@git.apache.org>.
Github user RahulNagekar commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/278#discussion_r238054315
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -9008,6 +9011,56 @@ public static String appendIfMissingIgnoreCase(final String str, final CharSeque
             return appendIfMissing(str, suffix, true, suffixes);
         }
     
    +    /**
    +     * <p>Returns either the passed in String with the specified suffix attached,
    +     * or if the String is empty ("")/{@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.appendIfNotBlank(null, " ")      = ""
    --- End diff --
    
    The javadoc needs an update to be in sync with the method name.


---

[GitHub] commons-lang pull request #278: Lang-1345 Enhance non-empty strings

Posted by garydgregory <gi...@git.apache.org>.
Github user garydgregory commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/278#discussion_r161277512
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -7429,6 +7429,55 @@ public static String defaultString(final String str, final String defaultStr) {
             return isEmpty(str) ? defaultStr : str;
         }
     
    +    // Extensions
    +    //-----------------------------------------------------------------------
    +
    +    /**
    +     * <p>Returns either the passed in String with the specified prefix and suffix attached,
    +     * or if the String is whitespace, empty ("") or {@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.extendIfNotBlank(null, "pre-", "-post")  = ""
    +     * StringUtils.extendIfNotBlank("", "pre-", "-post")    = ""
    +     * StringUtils.extendIfNotBlank(" ", "pre-", "-post")   = ""
    +     * StringUtils.extendIfNotBlank("bat", "pre-", "-post") = "pre-bat-bost"
    +     * StringUtils.extendIfNotBlank("bat", null, "-post")      = "bat-post"
    +     * StringUtils.extendIfNotBlank("bat", "pre-", null)      = "pre-bat"
    +     * </pre>
    +     * @param str the String to check, may be null
    +     * @param prefix  the string to prepend if not blank. Null will be converted to empty string.
    +     * @param suffix  the string to append if not blank. Null will be converted to empty string.
    +     * @return the passed in String with prefix and suffix added, or empty string
    +     * @see StringUtils#defaultString(String, String)
    +     */
    +    public static String extendIfNotBlank(final String str, final String prefix, final String suffix) {
    +        return isBlank(str) ? "" : defaultString(prefix) + str + defaultString(suffix);
    --- End diff --
    
    Reuse the EMPTY constant.


---

[GitHub] commons-lang pull request #278: Lang-1345 Enhance non-empty strings

Posted by RahulNagekar <gi...@git.apache.org>.
Github user RahulNagekar commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/278#discussion_r238055382
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -9109,6 +9162,56 @@ public static String prependIfMissingIgnoreCase(final String str, final CharSequ
             return prependIfMissing(str, prefix, true, prefixes);
         }
     
    +    /**
    +     * <p>Returns either the passed in String with the specified prefix attached,
    +     * or if the String is whitespace/empty ("")/{@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.prependIfNotEmpty(null, " ")     = ""
    +     * StringUtils.prependIfNotEmpty(null, "pre-")  = ""
    +     * StringUtils.prependIfNotEmpty("", "pre-")    = ""
    +     * StringUtils.prependIfNotEmpty(" ", " ")      = "  "
    +     * StringUtils.prependIfNotEmpty(" ", "pre-")   = "pre- "
    +     * StringUtils.prependIfNotEmpty("abc", null)   = "abc"
    +     * StringUtils.prependIfNotEmpty("abc", "")     = "abc"
    +     * StringUtils.prependIfNotEmpty("abc", " ")    = " abc"
    +     * StringUtils.prependIfNotEmpty("abc", "pre-") = "pre-abc"
    +     * </pre>
    +     * @param str the String to check, may be null
    +     * @param prefix  the string to prepend if 'str' is not blank. Null will be converted to empty string.
    +     * @return the passed in String with prefix added, or empty string
    +     */
    +    public static String prependIfNotEmpty(final String str, final String prefix) {
    +        return isEmpty(str) ? EMPTY : defaultString(prefix) + str;
    --- End diff --
    
    ```suggestion
            return isEmpty(str) ? str : defaultString(prefix) + str;
    ```


---

[GitHub] commons-lang issue #278: Lang-1345 Enhance non-empty strings

Posted by ThrawnCA <gi...@git.apache.org>.
Github user ThrawnCA commented on the issue:

    https://github.com/apache/commons-lang/pull/278
  
    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.


---

[GitHub] commons-lang issue #278: Lang-1345 Enhance non-empty strings

Posted by stokito <gi...@git.apache.org>.
Github user stokito commented on the issue:

    https://github.com/apache/commons-lang/pull/278
  
    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.


---

[GitHub] commons-lang issue #278: Lang-1345 Enhance non-empty strings

Posted by aaabramov <gi...@git.apache.org>.
Github user aaabramov commented on the issue:

    https://github.com/apache/commons-lang/pull/278
  
    > 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.


---

[GitHub] commons-lang issue #278: Lang-1345 Enhance non-empty strings

Posted by ThrawnCA <gi...@git.apache.org>.
Github user ThrawnCA commented on the issue:

    https://github.com/apache/commons-lang/pull/278
  
    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.


---

[GitHub] commons-lang issue #278: Lang-1345 Enhance non-empty strings

Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:

    https://github.com/apache/commons-lang/pull/278
  
    
    [![Coverage Status](https://coveralls.io/builds/12432196/badge)](https://coveralls.io/builds/12432196)
    
    Coverage increased (+0.0006%) to 95.168% when pulling **e89ca5ceb5dfbb5e2b94a9f5497c28ecf8c65973 on ThrawnCA:LANG-1345-enhance-non-empty-strings** into **187a05b8a4db364af9d1c8ff4eb422082c30a1ff on apache:master**.



---
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.
---

[GitHub] commons-lang pull request #278: Lang-1345 Enhance non-empty strings

Posted by RahulNagekar <gi...@git.apache.org>.
Github user RahulNagekar commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/278#discussion_r238054555
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -9008,6 +9011,56 @@ public static String appendIfMissingIgnoreCase(final String str, final CharSeque
             return appendIfMissing(str, suffix, true, suffixes);
         }
     
    +    /**
    +     * <p>Returns either the passed in String with the specified suffix attached,
    +     * or if the String is empty ("")/{@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.appendIfNotBlank(null, " ")      = ""
    +     * StringUtils.appendIfNotBlank(null, "-post")  = ""
    +     * StringUtils.appendIfNotBlank("", "-post")    = ""
    +     * StringUtils.appendIfNotBlank(" ", " ")       = "  "
    +     * StringUtils.appendIfNotBlank(" ", "-post")   = " -post"
    +     * StringUtils.appendIfNotBlank("abc", null)    = "abc"
    +     * StringUtils.appendIfNotBlank("abc", "")      = "abc"
    +     * StringUtils.appendIfNotBlank("abc", " ")     = "abc "
    +     * StringUtils.appendIfNotBlank("abc", "-post") = "abc-post"
    +     * </pre>
    +     * @param str the String to check, may be null
    +     * @param suffix  the string to append if 'str' is not empty. Null will be converted to empty string.
    +     * @return the passed in String with suffix added, or empty string
    +     */
    +    public static String appendIfNotEmpty(final String str, final String suffix) {
    +        return isEmpty(str) ? EMPTY : str + defaultString(suffix);
    +    }
    +
    +    /**
    +     * <p>Returns either the passed in String with the specified suffix attached,
    +     * or if the String is whitespace/empty ("")/{@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.appendIfNotBlank(null, " ")      = ""
    +     * StringUtils.appendIfNotBlank(null, "-post")  = ""
    +     * StringUtils.appendIfNotBlank("", "-post")    = ""
    +     * StringUtils.appendIfNotBlank(" ", " ")       = ""
    --- End diff --
    
    9050 : The method behavior doesn't seem to be in sync with its name for this test case. 
    Current behaviour :
    StringUtils.appendIfNotBlank(" ", "-post")   = ""
    Behavior as per the name:
    StringUtils.appendIfNotBlank(" ", "-post")   = " "
    
    May be should preserve the original string although if its blank.


---

[GitHub] commons-lang pull request #278: Lang-1345 Enhance non-empty strings

Posted by RahulNagekar <gi...@git.apache.org>.
Github user RahulNagekar commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/278#discussion_r238055353
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -9008,6 +9011,56 @@ public static String appendIfMissingIgnoreCase(final String str, final CharSeque
             return appendIfMissing(str, suffix, true, suffixes);
         }
     
    +    /**
    +     * <p>Returns either the passed in String with the specified suffix attached,
    +     * or if the String is empty ("")/{@code null}, an empty string.</p>
    +     *
    +     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.appendIfNotBlank(null, " ")      = ""
    +     * StringUtils.appendIfNotBlank(null, "-post")  = ""
    +     * StringUtils.appendIfNotBlank("", "-post")    = ""
    +     * StringUtils.appendIfNotBlank(" ", " ")       = "  "
    +     * StringUtils.appendIfNotBlank(" ", "-post")   = " -post"
    +     * StringUtils.appendIfNotBlank("abc", null)    = "abc"
    +     * StringUtils.appendIfNotBlank("abc", "")      = "abc"
    +     * StringUtils.appendIfNotBlank("abc", " ")     = "abc "
    +     * StringUtils.appendIfNotBlank("abc", "-post") = "abc-post"
    +     * </pre>
    +     * @param str the String to check, may be null
    +     * @param suffix  the string to append if 'str' is not empty. Null will be converted to empty string.
    +     * @return the passed in String with suffix added, or empty string
    +     */
    +    public static String appendIfNotEmpty(final String str, final String suffix) {
    +        return isEmpty(str) ? EMPTY : str + defaultString(suffix);
    --- End diff --
    
    ```suggestion
            return isEmpty(str) ? str : str + defaultString(suffix);
    ```


---