| 350 | } |
| 351 | |
| 352 | private static int parse(String string, int offset, int radix, |
| 353 | boolean negative) throws NumberFormatException { |
| 354 | int max = Integer.MIN_VALUE / radix; |
| 355 | int result = 0, length = string.length(); |
| 356 | while (offset < length) { |
| 357 | int digit = Character.digit(string.charAt(offset++), radix); |
| 358 | if (digit == -1) { |
| 359 | throw new NumberFormatException(string); |
| 360 | } |
| 361 | if (max > result) { |
| 362 | throw new NumberFormatException(string); |
| 363 | } |
| 364 | int next = result * radix - digit; |
| 365 | if (next > result) { |
| 366 | throw new NumberFormatException(string); |
| 367 | } |
| 368 | result = next; |
| 369 | } |
| 370 | if (!negative) { |
| 371 | result = -result; |
| 372 | if (result < 0) { |
| 373 | throw new NumberFormatException(string); |
| 374 | } |
| 375 | } |
| 376 | return result; |
| 377 | } |
| 378 | |
| 379 | @Override |
| 380 | public short shortValue() { |