mirror of
https://github.com/corda/corda.git
synced 2025-01-20 11:39:09 +00:00
implement Character.forDigit
This commit is contained in:
parent
2dcc1d525a
commit
b57e734ceb
@ -109,6 +109,15 @@ public final class Character implements Comparable<Character> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static char forDigit(int digit, int radix) {
|
||||||
|
if (MIN_RADIX <= radix && radix <= MAX_RADIX) {
|
||||||
|
if (0 <= digit && digit < radix) {
|
||||||
|
return (char) (digit < 10 ? digit + '0' : digit + 'a' - 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isLetter(int c) {
|
public static boolean isLetter(int c) {
|
||||||
return canCastToChar(c) && isLetter((char) c);
|
return canCastToChar(c) && isLetter((char) c);
|
||||||
}
|
}
|
||||||
|
@ -71,5 +71,11 @@ public class Strings {
|
|||||||
sb.append('$');
|
sb.append('$');
|
||||||
sb.append('2');
|
sb.append('2');
|
||||||
expect(sb.substring(1).equals("2"));
|
expect(sb.substring(1).equals("2"));
|
||||||
|
|
||||||
|
expect(Character.forDigit(Character.digit('0', 10), 10) == '0');
|
||||||
|
expect(Character.forDigit(Character.digit('9', 10), 10) == '9');
|
||||||
|
expect(Character.forDigit(Character.digit('b', 16), 16) == 'b');
|
||||||
|
expect(Character.forDigit(Character.digit('f', 16), 16) == 'f');
|
||||||
|
expect(Character.forDigit(Character.digit('z', 36), 36) == 'z');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user