You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2022/05/28 16:08:06 UTC
[GitHub] [commons-lang] arturobernalg opened a new pull request, #903: Add toCharacterObject(String,String) with default value.
arturobernalg opened a new pull request, #903:
URL: https://github.com/apache/commons-lang/pull/903
Create a new method that Converts the String to a Character using the first character, returning a
default value if null or empty is passed in.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] garydgregory commented on pull request #903: Add toCharacterObject(String,String) with default value.
Posted by GitBox <gi...@apache.org>.
garydgregory commented on PR #903:
URL: https://github.com/apache/commons-lang/pull/903#issuecomment-1140303630
Hello @arturobernalg
What is a use case for this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] codecov-commenter commented on pull request #903: Add toCharacterObject(String,String) with default value.
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #903:
URL: https://github.com/apache/commons-lang/pull/903#issuecomment-1140290398
# [Codecov](https://codecov.io/gh/apache/commons-lang/pull/903?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#903](https://codecov.io/gh/apache/commons-lang/pull/903?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (764b7a3) into [master](https://codecov.io/gh/apache/commons-lang/commit/65fb650380c063f1aece7e93d14e2052fc2ec747?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (65fb650) will **increase** coverage by `0.02%`.
> The diff coverage is `100.00%`.
> :exclamation: Current head 764b7a3 differs from pull request most recent head 8bafd0a. Consider uploading reports for the commit 8bafd0a to get more accurate results
```diff
@@ Coverage Diff @@
## master #903 +/- ##
============================================
+ Coverage 91.48% 91.51% +0.02%
- Complexity 7393 7400 +7
============================================
Files 188 188
Lines 15964 15973 +9
Branches 2999 3000 +1
============================================
+ Hits 14605 14617 +12
+ Misses 765 764 -1
+ Partials 594 592 -2
```
| [Impacted Files](https://codecov.io/gh/apache/commons-lang/pull/903?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [.../main/java/org/apache/commons/lang3/CharUtils.java](https://codecov.io/gh/apache/commons-lang/pull/903/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2NvbW1vbnMvbGFuZzMvQ2hhclV0aWxzLmphdmE=) | `100.00% <100.00%> (ø)` | |
| [...pache/commons/lang3/function/FailableConsumer.java](https://codecov.io/gh/apache/commons-lang/pull/903/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2NvbW1vbnMvbGFuZzMvZnVuY3Rpb24vRmFpbGFibGVDb25zdW1lci5qYXZh) | `71.42% <0.00%> (ø)` | |
| [...pache/commons/lang3/function/FailableFunction.java](https://codecov.io/gh/apache/commons-lang/pull/903/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2NvbW1vbnMvbGFuZzMvZnVuY3Rpb24vRmFpbGFibGVGdW5jdGlvbi5qYXZh) | `100.00% <0.00%> (ø)` | |
| [...ache/commons/lang3/function/FailablePredicate.java](https://codecov.io/gh/apache/commons-lang/pull/903/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2NvbW1vbnMvbGFuZzMvZnVuY3Rpb24vRmFpbGFibGVQcmVkaWNhdGUuamF2YQ==) | `77.77% <0.00%> (ø)` | |
| [...che/commons/lang3/function/FailableBiConsumer.java](https://codecov.io/gh/apache/commons-lang/pull/903/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2NvbW1vbnMvbGFuZzMvZnVuY3Rpb24vRmFpbGFibGVCaUNvbnN1bWVyLmphdmE=) | `71.42% <0.00%> (ø)` | |
| [...che/commons/lang3/function/FailableBiFunction.java](https://codecov.io/gh/apache/commons-lang/pull/903/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2NvbW1vbnMvbGFuZzMvZnVuY3Rpb24vRmFpbGFibGVCaUZ1bmN0aW9uLmphdmE=) | `100.00% <0.00%> (ø)` | |
| [...he/commons/lang3/function/FailableBiPredicate.java](https://codecov.io/gh/apache/commons-lang/pull/903/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2NvbW1vbnMvbGFuZzMvZnVuY3Rpb24vRmFpbGFibGVCaVByZWRpY2F0ZS5qYXZh) | `100.00% <0.00%> (ø)` | |
| [...he/commons/lang3/function/FailableIntConsumer.java](https://codecov.io/gh/apache/commons-lang/pull/903/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2NvbW1vbnMvbGFuZzMvZnVuY3Rpb24vRmFpbGFibGVJbnRDb25zdW1lci5qYXZh) | `71.42% <0.00%> (ø)` | |
| [...he/commons/lang3/function/FailableIntFunction.java](https://codecov.io/gh/apache/commons-lang/pull/903/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2NvbW1vbnMvbGFuZzMvZnVuY3Rpb24vRmFpbGFibGVJbnRGdW5jdGlvbi5qYXZh) | `0.00% <0.00%> (ø)` | |
| [...e/commons/lang3/function/FailableIntPredicate.java](https://codecov.io/gh/apache/commons-lang/pull/903/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2NvbW1vbnMvbGFuZzMvZnVuY3Rpb24vRmFpbGFibGVJbnRQcmVkaWNhdGUuamF2YQ==) | `100.00% <0.00%> (ø)` | |
| ... and [27 more](https://codecov.io/gh/apache/commons-lang/pull/903/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/commons-lang/pull/903?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/commons-lang/pull/903?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [65fb650...8bafd0a](https://codecov.io/gh/apache/commons-lang/pull/903?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] aherbert commented on a diff in pull request #903: Add toCharacterObject(String,String) with default value.
Posted by GitBox <gi...@apache.org>.
aherbert commented on code in PR #903:
URL: https://github.com/apache/commons-lang/pull/903#discussion_r884219852
##########
src/main/java/org/apache/commons/lang3/CharUtils.java:
##########
@@ -115,6 +115,33 @@ public static Character toCharacterObject(final String str) {
return Character.valueOf(str.charAt(0));
}
+ /**
+ * <p>Converts the String to a Character using the first character, returning a
+ * default value if {@code null} or empty is passed in.</p>
+ *
+ * <p>For ASCII 7 bit characters, this uses a cache that will return the
+ * same Character object each time.</p>
+ *
+ * <pre>
+ * CharUtils.toCharacterObject(null, 'A') = 'A'
+ * CharUtils.toCharacterObject("", 'A') = 'A'
+ * CharUtils.toCharacterObject("A") = 'A'
Review Comment:
These docs require updating too
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] class101 commented on a diff in pull request #903: Add toCharacterObject(String,String) with default value.
Posted by "class101 (via GitHub)" <gi...@apache.org>.
class101 commented on code in PR #903:
URL: https://github.com/apache/commons-lang/pull/903#discussion_r1246437527
##########
src/main/java/org/apache/commons/lang3/CharUtils.java:
##########
@@ -114,6 +114,33 @@ public static Character toCharacterObject(final String str) {
return StringUtils.isEmpty(str) ? null : Character.valueOf(str.charAt(0));
}
+ /**
+ * <p>Converts the String to a Character using the first character, returning a
+ * default value if {@code null} or empty is passed in.</p>
+ *
+ * <p>For ASCII 7 bit characters, this uses a cache that will return the
+ * same Character object each time.</p>
+ *
+ * <pre>
+ * CharUtils.toCharacterObject(null, 'A') = 'A'
+ * CharUtils.toCharacterObject("", 'A') = 'A'
+ * CharUtils.toCharacterObject("A", 'D') = 'A'
+ * CharUtils.toCharacterObject("BA", 'D') = 'B'
+ * </pre>
+ *
+ * @param str the character to convert
+ * @param defaultValue the value to use if the str is null or empty.
+ * @return the Character value of the first letter of the String or the default if null.
+ * @since 3.13.0
+ */
+ public static Character toCharacterObject(final String str, final Character defaultValue) {
+ final Character character = toCharacterObject(str);
+ if (character == null){
+ return defaultValue;
+ }
+ return character;
+ }
Review Comment:
I think of you still use ternary in 2023, you are a really bad developer
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] garydgregory commented on a diff in pull request #903: Add toCharacterObject(String,String) with default value.
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #903:
URL: https://github.com/apache/commons-lang/pull/903#discussion_r1246525305
##########
src/main/java/org/apache/commons/lang3/CharUtils.java:
##########
@@ -114,6 +114,33 @@ public static Character toCharacterObject(final String str) {
return StringUtils.isEmpty(str) ? null : Character.valueOf(str.charAt(0));
}
+ /**
+ * <p>Converts the String to a Character using the first character, returning a
+ * default value if {@code null} or empty is passed in.</p>
+ *
+ * <p>For ASCII 7 bit characters, this uses a cache that will return the
+ * same Character object each time.</p>
+ *
+ * <pre>
+ * CharUtils.toCharacterObject(null, 'A') = 'A'
+ * CharUtils.toCharacterObject("", 'A') = 'A'
+ * CharUtils.toCharacterObject("A", 'D') = 'A'
+ * CharUtils.toCharacterObject("BA", 'D') = 'B'
+ * </pre>
+ *
+ * @param str the character to convert
+ * @param defaultValue the value to use if the str is null or empty.
+ * @return the Character value of the first letter of the String or the default if null.
+ * @since 3.13.0
+ */
+ public static Character toCharacterObject(final String str, final Character defaultValue) {
+ final Character character = toCharacterObject(str);
+ if (character == null){
+ return defaultValue;
+ }
+ return character;
+ }
Review Comment:
> I think if you still uses ternary conditions in 2023, you are a really bad developer. For the love of god, understand ternaries are unreadable and are a very bad practice to show junior developers.
The ternary expression is an uncontroversial feature of the Java language as well as of most programming languages. This is the first time I've ever read anyone express dismay at its usage. For a great overview of best practices, I recommend Josh Block's Effective Java.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] arturobernalg closed pull request #903: Add toCharacterObject(String,String) with default value.
Posted by "arturobernalg (via GitHub)" <gi...@apache.org>.
arturobernalg closed pull request #903: Add toCharacterObject(String,String) with default value.
URL: https://github.com/apache/commons-lang/pull/903
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] class101 commented on a diff in pull request #903: Add toCharacterObject(String,String) with default value.
Posted by "class101 (via GitHub)" <gi...@apache.org>.
class101 commented on code in PR #903:
URL: https://github.com/apache/commons-lang/pull/903#discussion_r1246437527
##########
src/main/java/org/apache/commons/lang3/CharUtils.java:
##########
@@ -114,6 +114,33 @@ public static Character toCharacterObject(final String str) {
return StringUtils.isEmpty(str) ? null : Character.valueOf(str.charAt(0));
}
+ /**
+ * <p>Converts the String to a Character using the first character, returning a
+ * default value if {@code null} or empty is passed in.</p>
+ *
+ * <p>For ASCII 7 bit characters, this uses a cache that will return the
+ * same Character object each time.</p>
+ *
+ * <pre>
+ * CharUtils.toCharacterObject(null, 'A') = 'A'
+ * CharUtils.toCharacterObject("", 'A') = 'A'
+ * CharUtils.toCharacterObject("A", 'D') = 'A'
+ * CharUtils.toCharacterObject("BA", 'D') = 'B'
+ * </pre>
+ *
+ * @param str the character to convert
+ * @param defaultValue the value to use if the str is null or empty.
+ * @return the Character value of the first letter of the String or the default if null.
+ * @since 3.13.0
+ */
+ public static Character toCharacterObject(final String str, final Character defaultValue) {
+ final Character character = toCharacterObject(str);
+ if (character == null){
+ return defaultValue;
+ }
+ return character;
+ }
Review Comment:
I think if you still uses ternary conditions in 2023, you are a really bad developer. For the love of god, understand ternaries are unreadable and are a very bad practice to show junior developers.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] class101 commented on pull request #903: Add toCharacterObject(String,String) with default value.
Posted by GitBox <gi...@apache.org>.
class101 commented on PR #903:
URL: https://github.com/apache/commons-lang/pull/903#issuecomment-1379344780
> You can also look up the word "volunteer"... ;-)
Volunteers to clear the pull request queue ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] arturobernalg commented on pull request #903: Add toCharacterObject(String,String) with default value.
Posted by GitBox <gi...@apache.org>.
arturobernalg commented on PR #903:
URL: https://github.com/apache/commons-lang/pull/903#issuecomment-1140307770
> Hello @arturobernalg
> What is a use case for this?
HI @garydgregory
for exactly the same as the ` public static Character toCharacterObject(final String str)` function but avoiding null return values,
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] class101 commented on pull request #903: Add toCharacterObject(String,String) with default value.
Posted by GitBox <gi...@apache.org>.
class101 commented on PR #903:
URL: https://github.com/apache/commons-lang/pull/903#issuecomment-1378630195
I was wondering why lang3 has a release per year. Really not motivating in participating this project, 110 pull request my god….
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] kinow commented on a diff in pull request #903: Add toCharacterObject(String,String) with default value.
Posted by GitBox <gi...@apache.org>.
kinow commented on code in PR #903:
URL: https://github.com/apache/commons-lang/pull/903#discussion_r1067434485
##########
src/main/java/org/apache/commons/lang3/CharUtils.java:
##########
@@ -114,6 +114,33 @@ public static Character toCharacterObject(final String str) {
return StringUtils.isEmpty(str) ? null : Character.valueOf(str.charAt(0));
}
+ /**
+ * <p>Converts the String to a Character using the first character, returning a
+ * default value if {@code null} or empty is passed in.</p>
+ *
+ * <p>For ASCII 7 bit characters, this uses a cache that will return the
+ * same Character object each time.</p>
+ *
+ * <pre>
+ * CharUtils.toCharacterObject(null, 'A') = 'A'
+ * CharUtils.toCharacterObject("", 'A') = 'A'
+ * CharUtils.toCharacterObject("A", 'D') = 'A'
+ * CharUtils.toCharacterObject("BA", 'D') = 'B'
+ * </pre>
+ *
+ * @param str the character to convert
+ * @param defaultValue the value to use if the str is null or empty.
+ * @return the Character value of the first letter of the String or the default if null.
+ * @since 3.13.0
+ */
+ public static Character toCharacterObject(final String str, final Character defaultValue) {
+ final Character character = toCharacterObject(str);
+ if (character == null){
+ return defaultValue;
+ }
+ return character;
+ }
Review Comment:
I think the rest of the code is using 4 spaces (you used 4 spaces in the test).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] kinow commented on a diff in pull request #903: Add toCharacterObject(String,String) with default value.
Posted by GitBox <gi...@apache.org>.
kinow commented on code in PR #903:
URL: https://github.com/apache/commons-lang/pull/903#discussion_r1067443008
##########
src/main/java/org/apache/commons/lang3/CharUtils.java:
##########
@@ -114,6 +114,33 @@ public static Character toCharacterObject(final String str) {
return StringUtils.isEmpty(str) ? null : Character.valueOf(str.charAt(0));
}
+ /**
+ * <p>Converts the String to a Character using the first character, returning a
+ * default value if {@code null} or empty is passed in.</p>
+ *
+ * <p>For ASCII 7 bit characters, this uses a cache that will return the
+ * same Character object each time.</p>
+ *
+ * <pre>
+ * CharUtils.toCharacterObject(null, 'A') = 'A'
+ * CharUtils.toCharacterObject("", 'A') = 'A'
+ * CharUtils.toCharacterObject("A", 'D') = 'A'
+ * CharUtils.toCharacterObject("BA", 'D') = 'B'
+ * </pre>
+ *
+ * @param str the character to convert
Review Comment:
Also worth checking if the docs are ending sentences with dot or without it. I think this `@param` doesn't use that, but the next ones does.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] kinow commented on a diff in pull request #903: Add toCharacterObject(String,String) with default value.
Posted by GitBox <gi...@apache.org>.
kinow commented on code in PR #903:
URL: https://github.com/apache/commons-lang/pull/903#discussion_r1067442485
##########
src/main/java/org/apache/commons/lang3/CharUtils.java:
##########
@@ -114,6 +114,33 @@ public static Character toCharacterObject(final String str) {
return StringUtils.isEmpty(str) ? null : Character.valueOf(str.charAt(0));
}
+ /**
+ * <p>Converts the String to a Character using the first character, returning a
+ * default value if {@code null} or empty is passed in.</p>
+ *
+ * <p>For ASCII 7 bit characters, this uses a cache that will return the
+ * same Character object each time.</p>
+ *
+ * <pre>
+ * CharUtils.toCharacterObject(null, 'A') = 'A'
+ * CharUtils.toCharacterObject("", 'A') = 'A'
+ * CharUtils.toCharacterObject("A", 'D') = 'A'
+ * CharUtils.toCharacterObject("BA", 'D') = 'B'
+ * </pre>
+ *
+ * @param str the character to convert
Review Comment:
I think `str` is not a character too, sorry forgot to review the text in the javadocs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] garydgregory commented on pull request #903: Add toCharacterObject(String,String) with default value.
Posted by GitBox <gi...@apache.org>.
garydgregory commented on PR #903:
URL: https://github.com/apache/commons-lang/pull/903#issuecomment-1378687104
You can also look up the word "volunteer"... ;-)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] garydgregory commented on a diff in pull request #903: Add toCharacterObject(String,String) with default value.
Posted by GitBox <gi...@apache.org>.
garydgregory commented on code in PR #903:
URL: https://github.com/apache/commons-lang/pull/903#discussion_r1067475328
##########
src/main/java/org/apache/commons/lang3/CharUtils.java:
##########
@@ -114,6 +114,33 @@ public static Character toCharacterObject(final String str) {
return StringUtils.isEmpty(str) ? null : Character.valueOf(str.charAt(0));
}
+ /**
+ * <p>Converts the String to a Character using the first character, returning a
+ * default value if {@code null} or empty is passed in.</p>
+ *
+ * <p>For ASCII 7 bit characters, this uses a cache that will return the
+ * same Character object each time.</p>
+ *
+ * <pre>
+ * CharUtils.toCharacterObject(null, 'A') = 'A'
+ * CharUtils.toCharacterObject("", 'A') = 'A'
+ * CharUtils.toCharacterObject("A", 'D') = 'A'
+ * CharUtils.toCharacterObject("BA", 'D') = 'B'
+ * </pre>
+ *
+ * @param str the character to convert
+ * @param defaultValue the value to use if the str is null or empty.
+ * @return the Character value of the first letter of the String or the default if null.
+ * @since 3.13.0
+ */
+ public static Character toCharacterObject(final String str, final Character defaultValue) {
+ final Character character = toCharacterObject(str);
+ if (character == null){
+ return defaultValue;
+ }
+ return character;
+ }
Review Comment:
Better like this IMO: `return StringUtils.isEmpty(str) ? defaultValue : Character.valueOf(str.charAt(0));`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-lang] arturobernalg commented on a diff in pull request #903: Add toCharacterObject(String,String) with default value.
Posted by GitBox <gi...@apache.org>.
arturobernalg commented on code in PR #903:
URL: https://github.com/apache/commons-lang/pull/903#discussion_r884291959
##########
src/main/java/org/apache/commons/lang3/CharUtils.java:
##########
@@ -115,6 +115,33 @@ public static Character toCharacterObject(final String str) {
return Character.valueOf(str.charAt(0));
}
+ /**
+ * <p>Converts the String to a Character using the first character, returning a
+ * default value if {@code null} or empty is passed in.</p>
+ *
+ * <p>For ASCII 7 bit characters, this uses a cache that will return the
+ * same Character object each time.</p>
+ *
+ * <pre>
+ * CharUtils.toCharacterObject(null, 'A') = 'A'
+ * CharUtils.toCharacterObject("", 'A') = 'A'
+ * CharUtils.toCharacterObject("A") = 'A'
Review Comment:
thank you @aherbert
Fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org