commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LANG-1171) Add compare methods in StringUtils
Date Mon, 05 Oct 2015 13:07:27 GMT

    [ https://issues.apache.org/jira/browse/LANG-1171?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14943337#comment-14943337
] 

ASF GitHub Bot commented on LANG-1171:
--------------------------------------

GitHub user rikles opened a pull request:

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

    LANG-1171 Add null safe compare methods in StringUtils :

    Add null safe methods in `StringUtils` to compare 2 Strings :
    ```java
    public static int compare(final String str1, final String str2);
    public static int compare(final String str1, final String str2, final boolean nullIsLess);
    public static int compareIgnoreCase(final String str1, final String str2);
    public static int compareIgnoreCase(final String str1, final String str2, final boolean
nullIsLess);
    ```
    Those methods are null safe equivalent to :
    ```java
    str1.compareTo(str2);
    str1.compareToIgnoreCase(str2);
    ```

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

    $ git pull https://github.com/rikles/commons-lang fix-LANG-1171

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

    https://github.com/apache/commons-lang/pull/110.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 #110
    
----
commit 94ec5a11122b2e60fbffcc35373c978c839bf8ae
Author: Loic Guibert <lfdummy-apache@yahoo.fr>
Date:   2015-10-05T13:00:50Z

    LANG-1171 Add null safe compare methods in StringUtils :
      - StringUtils.compare(String str1, String str2);
      - StringUtils.compare(String str1, String str2, boolean nullIsLess);
      - StringUtils.compareIgnoreCase(String str1, String str2);
      - StringUtils.compareIgnoreCase(String str1, String str2, boolean nullIsLess);

----


> Add compare methods in StringUtils
> ----------------------------------
>
>                 Key: LANG-1171
>                 URL: https://issues.apache.org/jira/browse/LANG-1171
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Loic Guibert
>
> Add null safe methods in {{StringUtils}} to compare 2 Strings :
> {code:java}
> public static int compare(final String str1, final String str2);
> public static int compare(final String str1, final String str2, final boolean nullIsLess);
> public static int compareIgnoreCase(final String str1, final String str2);
> public static int compareIgnoreCase(final String str1, final String str2, final boolean
nullIsLess);
> {code}
> Those methods are null safe equivalent to :
> {code:java}
> String.compareTo(String);
> String.compareToIgnoreCase(String);
> {code}
> More details :
> {code:java}
> /**
>  * <p>Compare two Strings lexicographically, as per {@link String#compareTo(String)},
returning :</p>
>  * <ul>
>  *  <li>{@code int = 0}, if {@code str1} is equal to {@code str2} (or both {@code
null})</li>
>  *  <li>{@code int < 0}, if {@code str1} is less than {@code str2}</li>
>  *  <li>{@code int > 0}, if {@code str1} is greater than {@code str2}</li>
>  * </ul>
>  * 
>  * <p>This is a {@code null} safe version of :</p>
>  * <blockquote><pre>str1.compareTo(str2)</pre></blockquote>
>  * 
>  * <p>{@code null} value is considered less than non-{@code null} value.
>  * Two {@code null} references are considered equal.</p>
>  *
>  * <pre>
>  * StringUtils.compare(null, null)   = 0
>  * StringUtils.compare(null , "a")   &lt; 0
>  * StringUtils.compare("a", null)    &gt; 0
>  * StringUtils.compare("abc", "abc") = 0
>  * StringUtils.compare("a", "b")     &lt; 0
>  * StringUtils.compare("b", "a")     &gt; 0
>  * StringUtils.compare("a", "B")     &gt; 0
>  * StringUtils.compare("ab", "abc")  &lt; 0
>  * </pre>
>  *
>  * @see #compare(String, String, boolean)
>  * @see String#compareTo(String)
>  * @param str1  the String to compare from
>  * @param str2  the String to compare to
>  * @return &lt; 0, 0, &gt; 0, if {@code str1} is respectively less, equal ou
greater than {@code str2}
>  */
> public static int compare(final String str1, final String str2);
> /**
>  * <p>Compare two Strings lexicographically, as per {@link String#compareTo(String)},
returning :</p>
>  * <ul>
>  *  <li>{@code int = 0}, if {@code str1} is equal to {@code str2} (or both {@code
null})</li>
>  *  <li>{@code int < 0}, if {@code str1} is less than {@code str2}</li>
>  *  <li>{@code int > 0}, if {@code str1} is greater than {@code str2}</li>
>  * </ul>
>  * 
>  * <p>This is a {@code null} safe version of :</p>
>  * <blockquote><pre>str1.compareTo(str2)</pre></blockquote>
>  * 
>  * <p>{@code null} inputs are handled according to the {@code nullIsLess} parameter.
>  * Two {@code null} references are considered equal.</p>
>  *
>  * <pre>
>  * StringUtils.compare(null, null, *)     = 0
>  * StringUtils.compare(null , "a", true)  &lt; 0
>  * StringUtils.compare(null , "a", false) &gt; 0
>  * StringUtils.compare("a", null, true)   &gt; 0
>  * StringUtils.compare("a", null, false)  &lt; 0
>  * StringUtils.compare("abc", "abc", *)   = 0
>  * StringUtils.compare("a", "b", *)       &lt; 0
>  * StringUtils.compare("b", "a", *)       &gt; 0
>  * StringUtils.compare("a", "B", *)       &gt; 0
>  * StringUtils.compare("ab", "abc", *)    &lt; 0
>  * </pre>
>  *
>  * @see String#compareTo(String)
>  * @param str1  the String to compare from
>  * @param str2  the String to compare to
>  * @param nullIsLess  whether consider {@code null} value less than non-{@code null}
value
>  * @return &lt; 0, 0, &gt; 0, if {@code str1} is respectively less, equal ou
greater than {@code str2}
>  */
> public static int compare(final String str1, final String str2, final boolean nullIsLess);
> /**
>  * <p>Compare two Strings lexicographically, ignoring case differences,
>  * as per {@link String#compareToIgnoreCase(String)}, returning :</p>
>  * <ul>
>  *  <li>{@code int = 0}, if {@code str1} is equal to {@code str2} (or both {@code
null})</li>
>  *  <li>{@code int < 0}, if {@code str1} is less than {@code str2}</li>
>  *  <li>{@code int > 0}, if {@code str1} is greater than {@code str2}</li>
>  * </ul>
>  * 
>  * <p>This is a {@code null} safe version of :</p>
>  * <blockquote><pre>str1.compareToIgnoreCase(str2)</pre></blockquote>
>  * 
>  * <p>{@code null} value is considered less than non-{@code null} value.
>  * Two {@code null} references are considered equal.
>  * Comparison is case insensitive.</p>
>  *
>  * <pre>
>  * StringUtils.compareIgnoreCase(null, null)   = 0
>  * StringUtils.compareIgnoreCase(null , "a")   &lt; 0
>  * StringUtils.compareIgnoreCase("a", null)    &gt; 0
>  * StringUtils.compareIgnoreCase("abc", "abc") = 0
>  * StringUtils.compareIgnoreCase("abc", "ABC") = 0
>  * StringUtils.compareIgnoreCase("a", "b")     &lt; 0
>  * StringUtils.compareIgnoreCase("b", "a")     &gt; 0
>  * StringUtils.compareIgnoreCase("a", "B")     &lt; 0
>  * StringUtils.compareIgnoreCase("A", "b")     &lt; 0
>  * StringUtils.compareIgnoreCase("ab", "ABC")  &lt; 0
>  * </pre>
>  *
>  * @see #compareIgnoreCase(String, String, boolean)
>  * @see String#compareToIgnoreCase(String)
>  * @param str1  the String to compare from
>  * @param str2  the String to compare to
>  * @return &lt; 0, 0, &gt; 0, if {@code str1} is respectively less, equal ou
greater than {@code str2},
>  *          ignoring case differences.
>  */
> public static int compareIgnoreCase(final String str1, final String str2);
> /**
>  * <p>Compare two Strings lexicographically, ignoring case differences,
>  * as per {@link String#compareToIgnoreCase(String)}, returning :</p>
>  * <ul>
>  *  <li>{@code int = 0}, if {@code str1} is equal to {@code str2} (or both {@code
null})</li>
>  *  <li>{@code int < 0}, if {@code str1} is less than {@code str2}</li>
>  *  <li>{@code int > 0}, if {@code str1} is greater than {@code str2}</li>
>  * </ul>
>  * 
>  * <p>This is a {@code null} safe version of :</p>
>  * <blockquote><pre>str1.compareToIgnoreCase(str2)</pre></blockquote>
>  * 
>  * <p>{@code null} inputs are handled according to the {@code nullIsLess} parameter.
>  * Two {@code null} references are considered equal.
>  * Comparison is case insensitive.</p>
>  *
>  * <pre>
>  * StringUtils.compareIgnoreCase(null, null, *)     = 0
>  * StringUtils.compareIgnoreCase(null , "a", true)  &lt; 0
>  * StringUtils.compareIgnoreCase(null , "a", false) &gt; 0
>  * StringUtils.compareIgnoreCase("a", null, true)   &gt; 0
>  * StringUtils.compareIgnoreCase("a", null, false)  &lt; 0
>  * StringUtils.compareIgnoreCase("abc", "abc", *)   = 0
>  * StringUtils.compareIgnoreCase("abc", "ABC", *)   = 0
>  * StringUtils.compareIgnoreCase("a", "b", *)       &lt; 0
>  * StringUtils.compareIgnoreCase("b", "a", *)       &gt; 0
>  * StringUtils.compareIgnoreCase("a", "B", *)       &lt; 0
>  * StringUtils.compareIgnoreCase("A", "b", *)       &lt; 0
>  * StringUtils.compareIgnoreCase("ab", "abc", *)    &lt; 0
>  * </pre>
>  *
>  * @see String#compareToIgnoreCase(String)
>  * @param str1  the String to compare from
>  * @param str2  the String to compare to
>  * @param nullIsLess  whether consider {@code null} value less than non-{@code null}
value
>  * @return &lt; 0, 0, &gt; 0, if {@code str1} is respectively less, equal ou
greater than {@code str2},
>  *          ignoring case differences.
>  */
> public static int compareIgnoreCase(final String str1, final String str2, final boolean
nullIsLess);
> {code}
> I'm working on it and will send a pull request soon.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message