@Test public void parseDecimal() { Function<Object, BigDecimal> parser = s -> StringOptionUtil.parseDecimal(new StringOption(String.valueOf(s))); assertThat(parser.apply("0"), is(new BigDecimal("0"))); assertThat(parser.apply("1"), is(new BigDecimal("1"))); assertThat(parser.apply("+100"), is(new BigDecimal("100"))); assertThat(parser.apply("-100"), is(new BigDecimal("-100"))); assertThat(parser.apply("+3.14"), is(new BigDecimal("3.14"))); assertThat(parser.apply("-3.14"), is(new BigDecimal("-3.14"))); assertThat(parser.apply(Long.MAX_VALUE), is(new BigDecimal(Long.MAX_VALUE))); assertThat(parser.apply(Long.MIN_VALUE), is(new BigDecimal(Long.MIN_VALUE))); raise(() -> parser.apply("")); raise(() -> parser.apply("Hello, world!")); }
public static BigDecimal parseDecimal(StringOption contents) { CharBuffer buffer = DECODER_POOL.get().decode(contents.get()); if (buffer.hasRemaining() == false) { throw invalidNumber(contents); } int length = buffer.remaining(); if (buffer.hasArray()) { char[] array = buffer.array(); int offsetInArray = buffer.position() + buffer.arrayOffset(); return new BigDecimal(array, offsetInArray, length); } else { char[] cbuf = borrowCharArrayBuf(length); buffer.get(cbuf, 0, length); return new BigDecimal(cbuf, 0, length); } }
StringOptionUtil { public static BigDecimal parseDecimal(StringOption contents) { CharBuffer buffer = DECODER_POOL.get().decode(contents.get()); if (buffer.hasRemaining() == false) { throw invalidNumber(contents); } int length = buffer.remaining(); if (buffer.hasArray()) { char[] array = buffer.array(); int offsetInArray = buffer.position() + buffer.arrayOffset(); return new BigDecimal(array, offsetInArray, length); } else { char[] cbuf = borrowCharArrayBuf(length); buffer.get(cbuf, 0, length); return new BigDecimal(cbuf, 0, length); } } }
StringOptionUtil { public static BigDecimal parseDecimal(StringOption contents) { CharBuffer buffer = DECODER_POOL.get().decode(contents.get()); if (buffer.hasRemaining() == false) { throw invalidNumber(contents); } int length = buffer.remaining(); if (buffer.hasArray()) { char[] array = buffer.array(); int offsetInArray = buffer.position() + buffer.arrayOffset(); return new BigDecimal(array, offsetInArray, length); } else { char[] cbuf = borrowCharArrayBuf(length); buffer.get(cbuf, 0, length); return new BigDecimal(cbuf, 0, length); } } private  StringOptionUtil(); }
StringOptionUtil { public static BigDecimal parseDecimal(StringOption contents) { CharBuffer buffer = DECODER_POOL.get().decode(contents.get()); if (buffer.hasRemaining() == false) { throw invalidNumber(contents); } int length = buffer.remaining(); if (buffer.hasArray()) { char[] array = buffer.array(); int offsetInArray = buffer.position() + buffer.arrayOffset(); return new BigDecimal(array, offsetInArray, length); } else { char[] cbuf = borrowCharArrayBuf(length); buffer.get(cbuf, 0, length); return new BigDecimal(cbuf, 0, length); } } private  StringOptionUtil(); static int countCodePoints(StringOption option); static Reader asReader(StringOption option); static void trim(StringOption option); static void append(StringOption target, StringOption contents); static void append(StringOption target, String contents); static void append(StringBuilder target, StringOption contents); static int parseInt(StringOption contents); static long parseLong(StringOption contents); static BigDecimal parseDecimal(StringOption contents); static void append(
            CharBuffer source, StringOption destination,
            CharsetEncoder encoder, ByteBuffer buffer); }
StringOptionUtil { public static BigDecimal parseDecimal(StringOption contents) { CharBuffer buffer = DECODER_POOL.get().decode(contents.get()); if (buffer.hasRemaining() == false) { throw invalidNumber(contents); } int length = buffer.remaining(); if (buffer.hasArray()) { char[] array = buffer.array(); int offsetInArray = buffer.position() + buffer.arrayOffset(); return new BigDecimal(array, offsetInArray, length); } else { char[] cbuf = borrowCharArrayBuf(length); buffer.get(cbuf, 0, length); return new BigDecimal(cbuf, 0, length); } } private  StringOptionUtil(); static int countCodePoints(StringOption option); static Reader asReader(StringOption option); static void trim(StringOption option); static void append(StringOption target, StringOption contents); static void append(StringOption target, String contents); static void append(StringBuilder target, StringOption contents); static int parseInt(StringOption contents); static long parseLong(StringOption contents); static BigDecimal parseDecimal(StringOption contents); static void append(
            CharBuffer source, StringOption destination,
            CharsetEncoder encoder, ByteBuffer buffer); static final Charset ENCODING; }