@SuppressWarnings("deprecation") @Override public void addDouble(double value) { this.target.modify(value); } }
@SuppressWarnings("deprecation") @Override protected void setSpecial(CharSequence contents, Number value, DoubleOption property) { property.modify(value.doubleValue()); }
@SuppressWarnings("deprecation") @Override protected void set(BigDecimal value, DoubleOption property) { property.modify(value.doubleValue()); }
@SuppressWarnings("deprecation") @Override void modify(DoubleOption holder, Object value) { holder.modify(cast(Number.class, value).doubleValue()); } @Override
@SuppressWarnings("deprecation") @Override protected void doRead(ValueReader reader, DoubleOption property) throws IOException { double value = reader.readDouble(); property.modify(value); }
@SuppressWarnings("deprecation") @Override protected void doParseDefault(CharSequence contents, DoubleOption property) { property.modify(TextUtil.parseDouble(contents, 0, contents.length())); }
@SuppressWarnings("deprecation") @Override public void readFields(DataInput in) throws IOException { if (in.readBoolean()) { modify(decode(in.readLong())); } else { setNull(); } }
@SuppressWarnings("deprecation") @Override public void set(ValueOption<?> target, Object value) { if (value == null) { target.setNull(); } else { ((DoubleOption) target).modify(inspector.get(value)); } } }
@SuppressWarnings("deprecation") @Override public int restore(byte[] bytes, int offset, int limit) throws IOException { if (limit - offset == 0) { throw new IOException(MessageFormat.format( "Cannot restore a double field ({0})", "invalid length")); } if (bytes[offset + 0] == 0) { setNull(); return 1; } else if (limit - offset >= 1 + 1) { modify(decode(ByteArrayUtil.readLong(bytes, offset + 1))); return 8 + 1; } else { throw new IOException(MessageFormat.format( "Cannot restore a double field ({0})", "invalid length")); } }
@Override public void fill(DoubleOption option) throws RecordFormatException, IOException { checkCellStart(); if (applyNull(option)) { return; } assertHasRest(option, lookAhead); charBuffer[0] = (char) lookAhead; int length = readString(1, option); String string = new String(charBuffer, 0, length + 1); try { option.modify(Double.parseDouble(string)); } catch (NumberFormatException e) { Matcher matcher = SPECIAL_FLOAT.matcher(string); if (matcher.matches()) { if (matcher.group(SPECIAL_FLOAT_POSITIVE_INF) != null) { option.modify(Double.POSITIVE_INFINITY); } else if (matcher.group(SPECIAL_FLOAT_NEGATIVE_INF) != null) { option.modify(Double.NEGATIVE_INFINITY); } else { option.modify(Double.NaN); } } else { throw new RecordFormatException(MessageFormat.format( "Invalid character in floating-point context {0}", string), e); } } fillLookAhead(); }
@SuppressWarnings("deprecation") private void fill0(DoubleOption option, boolean doRecover) throws CsvFormatException { if (lineBuffer.hasRemaining()) { try { double value = Double.parseDouble(lineBuffer.toString()); option.modify(value); } catch (NumberFormatException e) { if (doRecover && trimWhitespaces()) { fill0(option, false); return; } throw new CsvFormatException(createStatusInLine(Reason.INVALID_CELL_FORMAT, "double value"), e); } } else { option.setNull(); } }
/** * test for or w/ present value. */ @Test public void orNotNull() { DoubleOption option = new DoubleOption(); option.modify(100); assertThat(option.or(30), is(100.d)); }
/** * test for get. */ @Test public void get() { DoubleOption option = new DoubleOption(); option.modify(100); assertThat(option.get(), is(100.d)); assertThat(option.isNull(), is(false)); }
/** * test for copyFrom w/ null. */ @Test public void copyNull() { DoubleOption option = new DoubleOption(); option.modify(100); DoubleOption other = new DoubleOption(); option.copyFrom(other); assertThat(option.isNull(), is(true)); option.modify(100); option.copyFrom(null); assertThat(option.isNull(), is(true)); }
/** * test for Writable. */ @Test public void write() { DoubleOption option = new DoubleOption(); option.modify(100); DoubleOption restored = restore(option); assertThat(restored.get(), is(option.get())); }
/** * test for Writable w/ min. */ @Test public void write_min() { DoubleOption option = new DoubleOption(); option.modify(Double.NEGATIVE_INFINITY); DoubleOption restored = restore(option); assertThat(restored.get(), is(option.get())); }
/** * test for Writable w/ max. */ @Test public void write_max() { DoubleOption option = new DoubleOption(); option.modify(Double.POSITIVE_INFINITY); DoubleOption restored = restore(option); assertThat(restored.get(), is(option.get())); }
/** * test for compare. */ @Test public void compareTo() { DoubleOption a = new DoubleOption(); DoubleOption b = new DoubleOption(); DoubleOption c = new DoubleOption(); DoubleOption d = new DoubleOption(); DoubleOption e = new DoubleOption(); a.modify(-10); b.modify(0); c.modify(50); d.modify(-10); e.modify(-30); assertThat(compare(a, b), lessThan(0)); assertThat(compare(b, c), lessThan(0)); assertThat(compare(c, a), greaterThan(0)); assertThat(compare(a, c), lessThan(0)); assertThat(compare(b, a), greaterThan(0)); assertThat(compare(c, b), greaterThan(0)); assertThat(compare(a, d), is(0)); assertThat(compare(a, e), greaterThan(0)); }
/** * test for compare w/ null. */ @Test public void compareNull() { DoubleOption a = new DoubleOption(); DoubleOption b = new DoubleOption(); DoubleOption c = new DoubleOption(); a.modify(Double.NEGATIVE_INFINITY); assertThat(compare(a, b), greaterThan(0)); assertThat(compare(b, a), lessThan(0)); assertThat(compare(b, c), is(0)); }