-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix duplicate toUpperCase() calls, use Locale.ROOT #158
base: main
Are you sure you want to change the base?
Conversation
@Supersuz what do you mean? Your comment is a bit confusing :) |
@shoeper I am not able to merge the changes in this repo. Either you can set up so that I can self-merge after approvals, or you need to merge it yourself. Thx! P.S. I think all |
While technically this might not be needed in this specific case, it is a good practice to be explicit about the locale.
Sorry, I don't really know. I cannot merge it. |
Looking at commit history, @drinckes and @JonMcPherson merged things recently. |
@@ -496,7 +498,7 @@ public static boolean isValidCode(String code) { | |||
if (code == null || code.length() < 2) { | |||
return false; | |||
} | |||
code = code.toUpperCase(); | |||
code = code.toUpperCase(Locale.ROOT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you wanted to remove all redundant calls of toUpperCase()
, it could be modified to something like this
public static boolean isValidCode(String code) {
return isValidCodeUpperCase(code.toUpperCase(Locale.ROOT));
}
private static boolean isValidCodeUpperCase(String code) {
// do validity checks without calling code.toUpperCase() redundantly
}
And the constructor would instead call !isValidCodeUpperCase(newCode)
.
Just a minor improvement...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing out the redundant call. It's so redundant, in fact, that I think we can just remove the one in the constructor since the code will be cast to uppercase in isValidCode().
Also, @drinckes is who you want for merging |
Maybe @zongweil can help. |
I'll take a look within the next couple days. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Please pull the latest changes and address these comments.
@@ -153,11 +154,12 @@ public double getEastLongitude() { | |||
* @constructor | |||
*/ | |||
public OpenLocationCode(String code) throws IllegalArgumentException { | |||
if (!isValidCode(code.toUpperCase())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can get rid of the code.toUpperCase() here all together, since we're calling it inside of isValidCode().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this is public, can we make that assumption and document it the constructor comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand your question here, can you rephrase? What assumption are you thinking we need to document?
@@ -496,7 +498,7 @@ public static boolean isValidCode(String code) { | |||
if (code == null || code.length() < 2) { | |||
return false; | |||
} | |||
code = code.toUpperCase(); | |||
code = code.toUpperCase(Locale.ROOT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing out the redundant call. It's so redundant, in fact, that I think we can just remove the one in the constructor since the code will be cast to uppercase in isValidCode().
This updates your version of OpenLocationCode.java to the most recent upstream version while keeping your changes.
Update to recent version while keeping changes
# Conflicts: # java/src/main/java/com/google/openlocationcode/OpenLocationCode.java
I have done another pass at minor optimizations -- the code now has a |
java/src/main/java/com/google/openlocationcode/OpenLocationCode.java
Outdated
Show resolved
Hide resolved
…e.java Co-authored-by: Sonya Alexandrova <[email protected]>
* @param code The code to check and normalize. | ||
* @return Normalized code if it is a valid full or short code, null otherwise. | ||
*/ | ||
private static String toValidCode(String code) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think returning an Optional instead of using null to signify invalid would be slightly cleaner here, what do you think?
@@ -153,11 +154,12 @@ public double getEastLongitude() { | |||
* @constructor | |||
*/ | |||
public OpenLocationCode(String code) throws IllegalArgumentException { | |||
if (!isValidCode(code.toUpperCase())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand your question here, can you rephrase? What assumption are you thinking we need to document?
Pinging everyone especially @nyurik to see if we can get the comments all resolved. |
No description provided.