You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by andyklimczak <gi...@git.apache.org> on 2016/12/30 02:57:52 UTC

[GitHub] commons-lang pull request #223: [LANG-1304] StringUtils method to check for ...

GitHub user andyklimczak opened a pull request:

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

    [LANG-1304] StringUtils method to check for mixed case in string

    [jira link](https://issues.apache.org/jira/browse/LANG-1304)

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

    $ git pull https://github.com/andyklimczak/commons-lang LANG-1304

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

    https://github.com/apache/commons-lang/pull/223.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 #223
    
----
commit da66668d4c6d93941c8b8ac62a4669fe4d57bbf6
Author: Andy Klimczak <an...@fastmail.com>
Date:   2016-12-30T02:01:12Z

    [LANG-1304] StringUtils method to check for mixed case in string

----


---
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 #223: [LANG-1304] StringUtils method to check for ...

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

    https://github.com/apache/commons-lang/pull/223#discussion_r94199781
  
    --- Diff: src/test/java/org/apache/commons/lang3/StringUtilsTest.java ---
    @@ -2563,6 +2563,24 @@ public void testIsAllUpperCase() {
             assertFalse(StringUtils.isAllUpperCase("A/C"));
         }
     
    +    /**
    +     * Test for {@link StringUtils#isMixedCase(CharSequence)}.
    +     */
    +    @Test
    +    public void testIsMixedCase() {
    +        assertFalse(StringUtils.isMixedCase(null));
    +        assertFalse(StringUtils.isMixedCase(StringUtils.EMPTY));
    +        assertFalse(StringUtils.isMixedCase(" "));
    +        assertTrue(StringUtils.isMixedCase("aBc"));
    +        assertFalse(StringUtils.isMixedCase("abc"));
    +        assertFalse(StringUtils.isMixedCase("ABC"));
    +        assertFalse(StringUtils.isMixedCase("aBc "));
    +        assertFalse(StringUtils.isMixedCase("A c"));
    +        assertFalse(StringUtils.isMixedCase("aBc\n"));
    +        assertFalse(StringUtils.isMixedCase("A1c"));
    +        assertFalse(StringUtils.isMixedCase("a/C"));
    --- End diff --
    
    Can you please add a test for a single character string? I think the implementation breaks when there is only a single character in the String/CharSequence


---
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 #223: [LANG-1304] StringUtils method to check for ...

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

    https://github.com/apache/commons-lang/pull/223#discussion_r94201194
  
    --- Diff: src/test/java/org/apache/commons/lang3/StringUtilsTest.java ---
    @@ -2563,6 +2563,24 @@ public void testIsAllUpperCase() {
             assertFalse(StringUtils.isAllUpperCase("A/C"));
         }
     
    +    /**
    +     * Test for {@link StringUtils#isMixedCase(CharSequence)}.
    +     */
    +    @Test
    +    public void testIsMixedCase() {
    +        assertFalse(StringUtils.isMixedCase(null));
    +        assertFalse(StringUtils.isMixedCase(StringUtils.EMPTY));
    +        assertFalse(StringUtils.isMixedCase(" "));
    +        assertTrue(StringUtils.isMixedCase("aBc"));
    +        assertFalse(StringUtils.isMixedCase("abc"));
    +        assertFalse(StringUtils.isMixedCase("ABC"));
    +        assertFalse(StringUtils.isMixedCase("aBc "));
    +        assertFalse(StringUtils.isMixedCase("A c"));
    +        assertFalse(StringUtils.isMixedCase("aBc\n"));
    +        assertFalse(StringUtils.isMixedCase("A1c"));
    +        assertFalse(StringUtils.isMixedCase("a/C"));
    --- End diff --
    
    Done, and I added a quick return case to skip going into the loop unnecessarily because a char sequence of length 1 cannot have both an upper and lowercase. 


---
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 #223: [LANG-1304] StringUtils method to check for ...

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

    https://github.com/apache/commons-lang/pull/223#discussion_r94200421
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -7193,6 +7193,45 @@ public static boolean isAllUpperCase(final CharSequence cs) {
             return true;
         }
     
    +    /**
    +     * <p>Checks if the CharSequence contains mixed casing of both uppercase and lowercase characters.</p>
    +     *
    +     * <p>{@code null} will return {@code false}.
    +     * An empty String (length()=0) will return {@code false}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.isMixedCase(null)    = false
    +     * StringUtils.isMixedCase("")      = false
    +     * StringUtils.isMixedCase("aBc")   = true
    +     * StringUtils.isMixedCase("ABC")   = false
    +     * StringUtils.isMixedCase("abc")   = false
    +     * StringUtils.isMixedCase("A c")   = false
    +     * StringUtils.isMixedCase("A1c")   = false
    +     * StringUtils.isMixedCase("a/C")   = false
    +     * </pre>
    +     *
    +     * @param cs the CharSequence to check, may be null
    +     * @return {@code true} if contains both uppercase and lowercase characters, and is non-null
    +     */
    +    public static boolean isMixedCase(final CharSequence cs) {
    +        if (cs == null || isEmpty(cs)) {
    +            return false;
    +        }
    +        boolean containsUppercase = false;
    +        boolean containsLowercase = false;
    +        final int sz = cs.length();
    +        for (int i = 0; i < sz; i++) {
    --- End diff --
    
    Almost, because consider the string "aB\n":
    It does contain a lowercase, then an uppercase, but it also contains the character '\n', which is a neither lower or uppercase. Breaking early would miss this case.


---
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 #223: [LANG-1304] StringUtils method to check for ...

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

    https://github.com/apache/commons-lang/pull/223#discussion_r94201247
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -7193,6 +7193,45 @@ public static boolean isAllUpperCase(final CharSequence cs) {
             return true;
         }
     
    +    /**
    +     * <p>Checks if the CharSequence contains mixed casing of both uppercase and lowercase characters.</p>
    +     *
    +     * <p>{@code null} will return {@code false}.
    +     * An empty String (length()=0) will return {@code false}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.isMixedCase(null)    = false
    +     * StringUtils.isMixedCase("")      = false
    +     * StringUtils.isMixedCase("aBc")   = true
    +     * StringUtils.isMixedCase("ABC")   = false
    +     * StringUtils.isMixedCase("abc")   = false
    +     * StringUtils.isMixedCase("A c")   = false
    +     * StringUtils.isMixedCase("A1c")   = false
    +     * StringUtils.isMixedCase("a/C")   = false
    +     * </pre>
    +     *
    +     * @param cs the CharSequence to check, may be null
    +     * @return {@code true} if contains both uppercase and lowercase characters, and is non-null
    +     */
    +    public static boolean isMixedCase(final CharSequence cs) {
    +        if (cs == null || isEmpty(cs)) {
    +            return false;
    +        }
    +        boolean containsUppercase = false;
    +        boolean containsLowercase = false;
    +        final int sz = cs.length();
    +        for (int i = 0; i < sz; i++) {
    --- End diff --
    
    In which case the name of the method should probably be changed? With a method name like `isMixedCase`, I would expect a return value of `true`.
    With your test string, yes there is the `\n` which is neither upper case or lower case, but the string has `a` and `B`, so it is mixed case.


---
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 #223: [LANG-1304] StringUtils method to check for ...

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

    https://github.com/apache/commons-lang/pull/223#discussion_r114111595
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -7193,6 +7193,45 @@ public static boolean isAllUpperCase(final CharSequence cs) {
             return true;
         }
     
    +    /**
    +     * <p>Checks if the CharSequence contains mixed casing of both uppercase and lowercase characters.</p>
    +     *
    +     * <p>{@code null} will return {@code false}.
    +     * An empty String (length()=0) will return {@code false}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.isMixedCase(null)    = false
    +     * StringUtils.isMixedCase("")      = false
    +     * StringUtils.isMixedCase("aBc")   = true
    +     * StringUtils.isMixedCase("ABC")   = false
    +     * StringUtils.isMixedCase("abc")   = false
    +     * StringUtils.isMixedCase("A c")   = false
    +     * StringUtils.isMixedCase("A1c")   = false
    +     * StringUtils.isMixedCase("a/C")   = false
    +     * </pre>
    +     *
    +     * @param cs the CharSequence to check, may be null
    +     * @return {@code true} if contains both uppercase and lowercase characters, and is non-null
    +     */
    +    public static boolean isMixedCase(final CharSequence cs) {
    +        if (cs == null || isEmpty(cs)) {
    +            return false;
    +        }
    +        boolean containsUppercase = false;
    +        boolean containsLowercase = false;
    +        final int sz = cs.length();
    +        for (int i = 0; i < sz; i++) {
    --- End diff --
    
    @arbasha I believe you requested this feature, what is your opinion on this?


---
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 issue #223: [LANG-1304] StringUtils method to check for mixed c...

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

    https://github.com/apache/commons-lang/pull/223
  
    
    [![Coverage Status](https://coveralls.io/builds/9467064/badge)](https://coveralls.io/builds/9467064)
    
    Coverage increased (+0.01%) to 94.373% when pulling **9bdede75d1a86d19a3aa37579dc2a9f93d558067 on andyklimczak:LANG-1304** into **021e4dfb501a8e6e5810a4f0efe1267810d62d64 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 issue #223: [LANG-1304] StringUtils method to check for mixed c...

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

    https://github.com/apache/commons-lang/pull/223
  
    
    [![Coverage Status](https://coveralls.io/builds/9466822/badge)](https://coveralls.io/builds/9466822)
    
    Coverage increased (+0.005%) to 94.367% when pulling **da66668d4c6d93941c8b8ac62a4669fe4d57bbf6 on andyklimczak:LANG-1304** into **021e4dfb501a8e6e5810a4f0efe1267810d62d64 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 #223: [LANG-1304] StringUtils method to check for ...

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

    https://github.com/apache/commons-lang/pull/223#discussion_r94199506
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -7193,6 +7193,45 @@ public static boolean isAllUpperCase(final CharSequence cs) {
             return true;
         }
     
    +    /**
    +     * <p>Checks if the CharSequence contains mixed casing of both uppercase and lowercase characters.</p>
    +     *
    +     * <p>{@code null} will return {@code false}.
    +     * An empty String (length()=0) will return {@code false}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.isMixedCase(null)    = false
    +     * StringUtils.isMixedCase("")      = false
    +     * StringUtils.isMixedCase("aBc")   = true
    +     * StringUtils.isMixedCase("ABC")   = false
    +     * StringUtils.isMixedCase("abc")   = false
    +     * StringUtils.isMixedCase("A c")   = false
    +     * StringUtils.isMixedCase("A1c")   = false
    +     * StringUtils.isMixedCase("a/C")   = false
    +     * </pre>
    +     *
    +     * @param cs the CharSequence to check, may be null
    +     * @return {@code true} if contains both uppercase and lowercase characters, and is non-null
    +     */
    +    public static boolean isMixedCase(final CharSequence cs) {
    +        if (cs == null || isEmpty(cs)) {
    +            return false;
    +        }
    +        boolean containsUppercase = false;
    +        boolean containsLowercase = false;
    +        final int sz = cs.length();
    +        for (int i = 0; i < sz; i++) {
    --- End diff --
    
    Wouldn't it be more efficient to track the case of the first character then break and return false on the first occurrence of the other case? Saves iterating the rest of the character sequence if it has mixed case.


---
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 #223: [LANG-1304] StringUtils method to check for ...

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

    https://github.com/apache/commons-lang/pull/223#discussion_r94203294
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -7193,6 +7193,45 @@ public static boolean isAllUpperCase(final CharSequence cs) {
             return true;
         }
     
    +    /**
    +     * <p>Checks if the CharSequence contains mixed casing of both uppercase and lowercase characters.</p>
    +     *
    +     * <p>{@code null} will return {@code false}.
    +     * An empty String (length()=0) will return {@code false}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.isMixedCase(null)    = false
    +     * StringUtils.isMixedCase("")      = false
    +     * StringUtils.isMixedCase("aBc")   = true
    +     * StringUtils.isMixedCase("ABC")   = false
    +     * StringUtils.isMixedCase("abc")   = false
    +     * StringUtils.isMixedCase("A c")   = false
    +     * StringUtils.isMixedCase("A1c")   = false
    +     * StringUtils.isMixedCase("a/C")   = false
    +     * </pre>
    +     *
    +     * @param cs the CharSequence to check, may be null
    +     * @return {@code true} if contains both uppercase and lowercase characters, and is non-null
    +     */
    +    public static boolean isMixedCase(final CharSequence cs) {
    +        if (cs == null || isEmpty(cs)) {
    +            return false;
    +        }
    +        boolean containsUppercase = false;
    +        boolean containsLowercase = false;
    +        final int sz = cs.length();
    +        for (int i = 0; i < sz; i++) {
    --- End diff --
    
    This method seems like a hybrid/sister method to ```isAllUppercase()``` and ```isAllLowercase()``` and treats non-alpha characters similarly.


---
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 issue #223: [LANG-1304] StringUtils method to check for mixed c...

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

    https://github.com/apache/commons-lang/pull/223
  
    hello friends, I've updated `isMixedCase()` to be much more accepting of special characters, numbers, and spaces. Please double check that my tests assert the strings correctly, and match the desired logic 
    
    Let me know if anything seems wrong ! 🐤 🔥 


---
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 #223: [LANG-1304] StringUtils method to check for ...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

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


---
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 #223: [LANG-1304] StringUtils method to check for ...

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

    https://github.com/apache/commons-lang/pull/223#discussion_r117889175
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -7193,6 +7193,45 @@ public static boolean isAllUpperCase(final CharSequence cs) {
             return true;
         }
     
    +    /**
    +     * <p>Checks if the CharSequence contains mixed casing of both uppercase and lowercase characters.</p>
    +     *
    +     * <p>{@code null} will return {@code false}.
    +     * An empty String (length()=0) will return {@code false}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.isMixedCase(null)    = false
    +     * StringUtils.isMixedCase("")      = false
    +     * StringUtils.isMixedCase("aBc")   = true
    +     * StringUtils.isMixedCase("ABC")   = false
    +     * StringUtils.isMixedCase("abc")   = false
    +     * StringUtils.isMixedCase("A c")   = false
    +     * StringUtils.isMixedCase("A1c")   = false
    +     * StringUtils.isMixedCase("a/C")   = false
    +     * </pre>
    +     *
    +     * @param cs the CharSequence to check, may be null
    +     * @return {@code true} if contains both uppercase and lowercase characters, and is non-null
    +     */
    +    public static boolean isMixedCase(final CharSequence cs) {
    +        if (cs == null || isEmpty(cs)) {
    +            return false;
    +        }
    +        boolean containsUppercase = false;
    +        boolean containsLowercase = false;
    +        final int sz = cs.length();
    +        for (int i = 0; i < sz; i++) {
    --- End diff --
    
    I missed this message before, will correct the logic sometime this week


---
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 issue #223: [LANG-1304] StringUtils method to check for mixed c...

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

    https://github.com/apache/commons-lang/pull/223
  
    
    [![Coverage Status](https://coveralls.io/builds/11661497/badge)](https://coveralls.io/builds/11661497)
    
    Coverage decreased (-0.002%) to 95.162% when pulling **3caf55722e992203f4e634ccd18bee9634b6e763 on andyklimczak:LANG-1304** into **9f2fe9bb80065fc249c61c897a0434e9ff48bbf6 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 issue #223: [LANG-1304] StringUtils method to check for mixed c...

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

    https://github.com/apache/commons-lang/pull/223
  
    Thanks! :+1: 


---
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 #223: [LANG-1304] StringUtils method to check for ...

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

    https://github.com/apache/commons-lang/pull/223#discussion_r114124824
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -7193,6 +7193,45 @@ public static boolean isAllUpperCase(final CharSequence cs) {
             return true;
         }
     
    +    /**
    +     * <p>Checks if the CharSequence contains mixed casing of both uppercase and lowercase characters.</p>
    +     *
    +     * <p>{@code null} will return {@code false}.
    +     * An empty String (length()=0) will return {@code false}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.isMixedCase(null)    = false
    +     * StringUtils.isMixedCase("")      = false
    +     * StringUtils.isMixedCase("aBc")   = true
    +     * StringUtils.isMixedCase("ABC")   = false
    +     * StringUtils.isMixedCase("abc")   = false
    +     * StringUtils.isMixedCase("A c")   = false
    +     * StringUtils.isMixedCase("A1c")   = false
    +     * StringUtils.isMixedCase("a/C")   = false
    +     * </pre>
    +     *
    +     * @param cs the CharSequence to check, may be null
    +     * @return {@code true} if contains both uppercase and lowercase characters, and is non-null
    +     */
    +    public static boolean isMixedCase(final CharSequence cs) {
    +        if (cs == null || isEmpty(cs)) {
    +            return false;
    +        }
    +        boolean containsUppercase = false;
    +        boolean containsLowercase = false;
    +        final int sz = cs.length();
    +        for (int i = 0; i < sz; i++) {
    --- End diff --
    
    Hi, @PascalSchumacher I second @bindul's point, this method should return true if the CharSequence has at least one upperCase and one lowerCase character. As a requester of this feature I would like to see this method behave that way.
     
     


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