| 342 | } |
| 343 | |
| 344 | private static long parse(String string, int offset, int radix, |
| 345 | boolean negative) { |
| 346 | long max = Long.MIN_VALUE / radix; |
| 347 | long result = 0, length = string.length(); |
| 348 | while (offset < length) { |
| 349 | int digit = Character.digit(string.charAt(offset++), radix); |
| 350 | if (digit == -1) { |
| 351 | throw new NumberFormatException(string); |
| 352 | } |
| 353 | if (max > result) { |
| 354 | throw new NumberFormatException(string); |
| 355 | } |
| 356 | long next = result * radix - digit; |
| 357 | if (next > result) { |
| 358 | throw new NumberFormatException(string); |
| 359 | } |
| 360 | result = next; |
| 361 | } |
| 362 | if (!negative) { |
| 363 | result = -result; |
| 364 | if (result < 0) { |
| 365 | throw new NumberFormatException(string); |
| 366 | } |
| 367 | } |
| 368 | return result; |
| 369 | } |
| 370 | |
| 371 | @Override |
| 372 | public short shortValue() { |