mirror of
https://github.com/corda/corda.git
synced 2025-01-05 20:54:13 +00:00
Add the Integer#decode method
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
parent
c1ec6020a6
commit
d04cda30ca
@ -122,4 +122,21 @@ public final class Integer extends Number implements Comparable<Integer> {
|
||||
public static int parseInt(String s, int radix) {
|
||||
return (int) Long.parseLong(s, radix);
|
||||
}
|
||||
|
||||
public static Integer decode(String string) {
|
||||
if (string.startsWith("-")) {
|
||||
if (string.startsWith("-0") || string.startsWith("-#")) {
|
||||
return new Integer(-decode(string.substring(1)));
|
||||
}
|
||||
} else if (string.startsWith("0")) {
|
||||
char c = string.length() < 2 ? (char)-1 : string.charAt(1);
|
||||
if (c == 'x' || c == 'X') {
|
||||
return new Integer(parseInt(string.substring(2), 0x10));
|
||||
}
|
||||
return new Integer(parseInt(string, 010));
|
||||
} else if (string.startsWith("#")) {
|
||||
return new Integer(parseInt(string.substring(1), 0x10));
|
||||
}
|
||||
return new Integer(parseInt(string, 10));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user