@SuppressWarnings("deprecation") @Override public void addFloat(float value) { this.target.modify(value); } }
@SuppressWarnings("deprecation") @Override protected void setSpecial(CharSequence contents, Number value, FloatOption property) { property.modify(value.floatValue()); }
@SuppressWarnings("deprecation") @Override protected void set(BigDecimal value, FloatOption property) { property.modify(value.floatValue()); }
@SuppressWarnings("deprecation") @Override protected void doParseDefault(CharSequence contents, FloatOption property) { property.modify(TextUtil.parseFloat(contents, 0, contents.length())); }
@SuppressWarnings("deprecation") @Override void modify(FloatOption holder, Object value) { holder.modify(cast(Number.class, value).floatValue()); } @Override
@SuppressWarnings("deprecation") @Override protected void doRead(ValueReader reader, FloatOption property) throws IOException { float value = reader.readFloat(); property.modify(value); }
@SuppressWarnings("deprecation") @Override public void readFields(DataInput in) throws IOException { if (in.readBoolean()) { modify(decode(in.readInt())); } else { setNull(); } }
@SuppressWarnings("deprecation") @Override public void set(ValueOption<?> target, Object value) { if (value == null) { target.setNull(); } else { ((FloatOption) target).modify(inspector.get(value)); } } }
@Override public void fill(FloatOption 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(Float.parseFloat(string)); } catch (NumberFormatException e) { Matcher matcher = SPECIAL_FLOAT.matcher(string); if (matcher.matches()) { if (matcher.group(SPECIAL_FLOAT_POSITIVE_INF) != null) { option.modify(Float.POSITIVE_INFINITY); } else if (matcher.group(SPECIAL_FLOAT_NEGATIVE_INF) != null) { option.modify(Float.NEGATIVE_INFINITY); } else { option.modify(Float.NaN); } } else { throw new RecordFormatException(MessageFormat.format( "Invalid character in floating-point context {0}", string), e); } } fillLookAhead(); }
@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 float field ({0})", "invalid length")); } if (bytes[offset + 0] == 0) { setNull(); return 1; } else if (limit - offset >= 1 + 1) { modify(decode(ByteArrayUtil.readInt(bytes, offset + 1))); return 4 + 1; } else { throw new IOException(MessageFormat.format( "Cannot restore a float field ({0})", "invalid length")); } }
@SuppressWarnings("deprecation") private void fill0(FloatOption option, boolean doRecover) throws CsvFormatException { if (lineBuffer.hasRemaining()) { try { float value = Float.parseFloat(lineBuffer.toString()); option.modify(value); } catch (NumberFormatException e) { if (doRecover && trimWhitespaces()) { fill0(option, false); return; } throw new CsvFormatException(createStatusInLine(Reason.INVALID_CELL_FORMAT, "float value"), e); } } else { option.setNull(); } }
/** * test for or w/ present value. */ @Test public void orNotNull() { FloatOption option = new FloatOption(); option.modify(100); assertThat(option.or(30), is(100.f)); }
/** * test for get. */ @Test public void get() { FloatOption option = new FloatOption(); option.modify(100); assertThat(option.get(), is(100.f)); assertThat(option.isNull(), is(false)); }
/** * test for copyFrom w/ null. */ @Test public void copyNull() { FloatOption option = new FloatOption(); option.modify(100); FloatOption other = new FloatOption(); option.copyFrom(other); assertThat(option.isNull(), is(true)); option.modify(100); option.copyFrom(null); assertThat(option.isNull(), is(true)); }
/** * test for Writable w/ max. */ @Test public void write_max() { FloatOption option = new FloatOption(); option.modify(Float.POSITIVE_INFINITY); FloatOption restored = restore(option); assertThat(restored.get(), is(option.get())); }
/** * test for Writable w/ min. */ @Test public void write_0() { FloatOption option = new FloatOption(); option.modify(0); FloatOption restored = restore(option); assertThat(restored.get(), is(option.get())); }
/** * test for Writable. */ @Test public void write() { FloatOption option = new FloatOption(); option.modify(100); FloatOption restored = restore(option); assertThat(restored.get(), is(option.get())); }
/** * test for compare. */ @Test public void compareTo() { FloatOption a = new FloatOption(); FloatOption b = new FloatOption(); FloatOption c = new FloatOption(); FloatOption d = new FloatOption(); FloatOption e = new FloatOption(); a.modify(-10); b.modify(0); c.modify(30); 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(d, e), greaterThan(0)); }
/** * test for comapre w/ null. */ @Test public void compareNull() { FloatOption a = new FloatOption(); FloatOption b = new FloatOption(); FloatOption c = new FloatOption(); a.modify(Float.NEGATIVE_INFINITY); assertThat(compare(a, b), greaterThan(0)); assertThat(compare(b, a), lessThan(0)); assertThat(compare(b, c), is(0)); }