@Test public void testDecodeBigInteger() throws ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { final Object[][] testParameters = new Object[][] {{"012", new BigInteger("10")}, {"-014", new BigInteger("-12")}, {"16", new BigInteger("16")}, {"-16", new BigInteger("-16")}, {"0x18", new BigInteger("24")}, {"-0X20", new BigInteger("-32")}, {"#22", new BigInteger("34")}, {"-#24", new BigInteger("-36")}}; for (final Object[] testParameter : testParameters) { BigInteger expected = (BigInteger) testParameter[1]; String value = (String) testParameter[0]; Method method = NumberUtils.class.getDeclaredMethod("decodeBigInteger", String.class); method.setAccessible(true); assertEquals(expected, method.invoke(NumberUtils.class, value)); } }
private static BigInteger decodeBigInteger(final String value) { int radix = 10; int index = 0; boolean negative = false; if (value.startsWith("-")) { negative = true; ++index; } if (value.startsWith("0x", index) || value.startsWith("0X", index)) { index += 2; radix = 16; } else if (value.startsWith("#", index)) { ++index; radix = 16; } else if (value.startsWith("0", index) && 1 + index < value.length()) { ++index; radix = 8; } final BigInteger result = new BigInteger(value.substring(index), radix); return (negative ? result.negate() : result); }
NumberUtils { private static BigInteger decodeBigInteger(final String value) { int radix = 10; int index = 0; boolean negative = false; if (value.startsWith("-")) { negative = true; ++index; } if (value.startsWith("0x", index) || value.startsWith("0X", index)) { index += 2; radix = 16; } else if (value.startsWith("#", index)) { ++index; radix = 16; } else if (value.startsWith("0", index) && 1 + index < value.length()) { ++index; radix = 8; } final BigInteger result = new BigInteger(value.substring(index), radix); return (negative ? result.negate() : result); } }
NumberUtils { private static BigInteger decodeBigInteger(final String value) { int radix = 10; int index = 0; boolean negative = false; if (value.startsWith("-")) { negative = true; ++index; } if (value.startsWith("0x", index) || value.startsWith("0X", index)) { index += 2; radix = 16; } else if (value.startsWith("#", index)) { ++index; radix = 16; } else if (value.startsWith("0", index) && 1 + index < value.length()) { ++index; radix = 8; } final BigInteger result = new BigInteger(value.substring(index), radix); return (negative ? result.negate() : result); }  }
NumberUtils { private static BigInteger decodeBigInteger(final String value) { int radix = 10; int index = 0; boolean negative = false; if (value.startsWith("-")) { negative = true; ++index; } if (value.startsWith("0x", index) || value.startsWith("0X", index)) { index += 2; radix = 16; } else if (value.startsWith("#", index)) { ++index; radix = 16; } else if (value.startsWith("0", index) && 1 + index < value.length()) { ++index; radix = 8; } final BigInteger result = new BigInteger(value.substring(index), radix); return (negative ? result.negate() : result); }  @SuppressWarnings("unchecked") static T convert(final Number number, final Class<T> targetClass); @SuppressWarnings("unchecked") static T parse(final String text, final Class<?> clazz); static T parse(final String text, final Class<T> targetClass,
      final NumberFormat numberFormat); static byte[] positiveToByteArray(final BigInteger positiveNumber); static BigInteger byteArrayToPositive(final byte[] rawBytes); }
NumberUtils { private static BigInteger decodeBigInteger(final String value) { int radix = 10; int index = 0; boolean negative = false; if (value.startsWith("-")) { negative = true; ++index; } if (value.startsWith("0x", index) || value.startsWith("0X", index)) { index += 2; radix = 16; } else if (value.startsWith("#", index)) { ++index; radix = 16; } else if (value.startsWith("0", index) && 1 + index < value.length()) { ++index; radix = 8; } final BigInteger result = new BigInteger(value.substring(index), radix); return (negative ? result.negate() : result); }  @SuppressWarnings("unchecked") static T convert(final Number number, final Class<T> targetClass); @SuppressWarnings("unchecked") static T parse(final String text, final Class<?> clazz); static T parse(final String text, final Class<T> targetClass,
      final NumberFormat numberFormat); static byte[] positiveToByteArray(final BigInteger positiveNumber); static BigInteger byteArrayToPositive(final byte[] rawBytes);  }