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

2017-05-25 Thread asfgit
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


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

2017-05-22 Thread andyklimczak
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;
 }
 
+/**
+ * Checks if the CharSequence contains mixed casing of both 
uppercase and lowercase characters.
+ *
+ * {@code null} will return {@code false}.
+ * An empty String (length()=0) will return {@code false}.
+ *
+ * 
+ * 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
+ * 
+ *
+ * @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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


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

2017-05-01 Thread arbasha
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;
 }
 
+/**
+ * Checks if the CharSequence contains mixed casing of both 
uppercase and lowercase characters.
+ *
+ * {@code null} will return {@code false}.
+ * An empty String (length()=0) will return {@code false}.
+ *
+ * 
+ * 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
+ * 
+ *
+ * @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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


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

2017-05-01 Thread PascalSchumacher
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;
 }
 
+/**
+ * Checks if the CharSequence contains mixed casing of both 
uppercase and lowercase characters.
+ *
+ * {@code null} will return {@code false}.
+ * An empty String (length()=0) will return {@code false}.
+ *
+ * 
+ * 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
+ * 
+ *
+ * @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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


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

2016-12-29 Thread andyklimczak
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;
 }
 
+/**
+ * Checks if the CharSequence contains mixed casing of both 
uppercase and lowercase characters.
+ *
+ * {@code null} will return {@code false}.
+ * An empty String (length()=0) will return {@code false}.
+ *
+ * 
+ * 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
+ * 
+ *
+ * @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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


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

2016-12-29 Thread andyklimczak
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


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

2016-12-29 Thread andyklimczak
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;
 }
 
+/**
+ * Checks if the CharSequence contains mixed casing of both 
uppercase and lowercase characters.
+ *
+ * {@code null} will return {@code false}.
+ * An empty String (length()=0) will return {@code false}.
+ *
+ * 
+ * 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
+ * 
+ *
+ * @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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


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

2016-12-29 Thread bindul
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


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

2016-12-29 Thread bindul
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;
 }
 
+/**
+ * Checks if the CharSequence contains mixed casing of both 
uppercase and lowercase characters.
+ *
+ * {@code null} will return {@code false}.
+ * An empty String (length()=0) will return {@code false}.
+ *
+ * 
+ * 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
+ * 
+ *
+ * @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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


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

2016-12-29 Thread andyklimczak
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 da8d4c6d93941c8b8ac62a4669fe4d57bbf6
Author: Andy Klimczak 
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---