@Test void testAsInteger() { assertThrows(RpcValueException.class, plainStringValue::asInteger); assertEquals(new BigInteger("0102030405", 16), bytesValue.asInteger()); assertEquals(new BigInteger("1234"), oddIntegerValue.asInteger()); assertEquals(new BigInteger("61731"), evenIntegerValue.asInteger()); assertEquals(new BigInteger("1"), booleanValue.asInteger()); RpcValue minusHex = new RpcValue("-0x4d2"); assertEquals(new BigInteger("-1234"), minusHex.asInteger()); RpcValue plusHex = new RpcValue("+0x4d2"); assertThrows(RpcValueException.class, plusHex::asInteger); }
@Override public BigInteger asInteger() { if (!(value.startsWith(HEX_PREFIX) || value.startsWith('-' + HEX_PREFIX))) { throw new RpcValueException("The value is not hex string."); } try { String sign = ""; if (value.charAt(0) == '-') { sign = value.substring(0, 1); value = value.substring(1); } String result = sign + Bytes.cleanHexPrefix(value); return new BigInteger(result, 16); } catch (NumberFormatException e) { throw new RpcValueException("The value is not hex string."); } }
RpcValue implements RpcItem { @Override public BigInteger asInteger() { if (!(value.startsWith(HEX_PREFIX) || value.startsWith('-' + HEX_PREFIX))) { throw new RpcValueException("The value is not hex string."); } try { String sign = ""; if (value.charAt(0) == '-') { sign = value.substring(0, 1); value = value.substring(1); } String result = sign + Bytes.cleanHexPrefix(value); return new BigInteger(result, 16); } catch (NumberFormatException e) { throw new RpcValueException("The value is not hex string."); } } }
RpcValue implements RpcItem { @Override public BigInteger asInteger() { if (!(value.startsWith(HEX_PREFIX) || value.startsWith('-' + HEX_PREFIX))) { throw new RpcValueException("The value is not hex string."); } try { String sign = ""; if (value.charAt(0) == '-') { sign = value.substring(0, 1); value = value.substring(1); } String result = sign + Bytes.cleanHexPrefix(value); return new BigInteger(result, 16); } catch (NumberFormatException e) { throw new RpcValueException("The value is not hex string."); } } RpcValue(RpcValue value);  RpcValue(Address value); private  RpcValue();  RpcValue(String value);  RpcValue(byte[] value);  RpcValue(BigInteger value);  RpcValue(boolean value);  RpcValue(Boolean value);  RpcValue(Bytes value); }
RpcValue implements RpcItem { @Override public BigInteger asInteger() { if (!(value.startsWith(HEX_PREFIX) || value.startsWith('-' + HEX_PREFIX))) { throw new RpcValueException("The value is not hex string."); } try { String sign = ""; if (value.charAt(0) == '-') { sign = value.substring(0, 1); value = value.substring(1); } String result = sign + Bytes.cleanHexPrefix(value); return new BigInteger(result, 16); } catch (NumberFormatException e) { throw new RpcValueException("The value is not hex string."); } } RpcValue(RpcValue value);  RpcValue(Address value); private  RpcValue();  RpcValue(String value);  RpcValue(byte[] value);  RpcValue(BigInteger value);  RpcValue(boolean value);  RpcValue(Boolean value);  RpcValue(Bytes value); @Override boolean isEmpty(); @Override boolean isNull(); @Override String asString(); @Override byte[] asByteArray(); @Override Address asAddress(); @Override Bytes asBytes(); @Override BigInteger asInteger(); @Override Boolean asBoolean(); @Override String toString(); }
RpcValue implements RpcItem { @Override public BigInteger asInteger() { if (!(value.startsWith(HEX_PREFIX) || value.startsWith('-' + HEX_PREFIX))) { throw new RpcValueException("The value is not hex string."); } try { String sign = ""; if (value.charAt(0) == '-') { sign = value.substring(0, 1); value = value.substring(1); } String result = sign + Bytes.cleanHexPrefix(value); return new BigInteger(result, 16); } catch (NumberFormatException e) { throw new RpcValueException("The value is not hex string."); } } RpcValue(RpcValue value);  RpcValue(Address value); private  RpcValue();  RpcValue(String value);  RpcValue(byte[] value);  RpcValue(BigInteger value);  RpcValue(boolean value);  RpcValue(Boolean value);  RpcValue(Bytes value); @Override boolean isEmpty(); @Override boolean isNull(); @Override String asString(); @Override byte[] asByteArray(); @Override Address asAddress(); @Override Bytes asBytes(); @Override BigInteger asInteger(); @Override Boolean asBoolean(); @Override String toString(); final static RpcValue NULL; }