-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
LANG-1644 - Check if number is hexadecimal #727
Conversation
You should really run a local build before creating the PR as this PR fails the build. |
Yep, my mistake. Sorry. |
return false; | ||
} | ||
} | ||
for (; i < chars.length; i++) { |
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.
Would be a neat use of our Range class?
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.
don't you think this may be complicated the code? are you thinking in a global solution, implement in isCreatable perhaps?
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.
Hi @garydgregory
I've trying use Range and i think it's more clean check the one by one the char. With range should look like:
final Range<Integer> range = Range.between(0, 15);
for (; pfxLen < chars.length; pfxLen++) {
if (!range.contains(Character.getNumericValue(chars[pfxLen]))) {
return false;
}
}
final char[] chars = str.toCharArray(); | ||
final int length = chars.length; | ||
int i = 1; | ||
if (chars[i] == 'x' || chars[i] == 'X') { |
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 chars is length 1 then this will throw an index out of bounds exception.
Is the intention that this should match public static boolean isCreatable(final String str)
public static Number createNumber(final String str) If so then you should support the I would then update the test to use all the hex cases from the tests for Currently your test only covers a range of It will also fail on valid hex numbers such as |
Hi @aherbert Thank you for your comment. I've fix those cases that you mentioned and i've add more test. Just one think about -->
|
Regarding I am not sure that allowing the number This method then becomes a subset of |
HI @aherbert Depends on what we want to achieve with the method. |
The value For example the following is valid hex So what is the use case for a method that identifies if a string has only valid hexidecimal digits and optionally a minus and a hex prefix? |
Hi @aherbert I will follow your approach. Regards |
Checks whether the given String is a hex number.