@SuppressWarnings("deprecation") @Override public void addFloat(float value) { this.target.modify(value); } }
@Override protected ValueOption<?> newObject() { return new FloatOption(); }
/** * 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 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 copyFrom. */ @Test public void copy() { FloatOption option = new FloatOption(); FloatOption other = new FloatOption(); other.modify(50); option.copyFrom(other); assertThat(option.get(), is(50.f)); option.modify(0); assertThat(other.get(), is(50.f)); }
"0,1,50,-1,-50," + "0.5,-0.5,100.,-100., 0,0 ,"); FloatOption option = new FloatOption(); assertThat(option.get(), is((float) 0)); assertThat(option.get(), is((float) 1)); assertThat(option.get(), is((float) 50)); assertThat(option.get(), is((float) -1)); assertThat(option.get(), is((float) -50)); assertThat(option.get(), is((float) 0.5)); assertThat(option.get(), is((float) -0.5)); assertThat(option.get(), is((float) 100.)); assertThat(option.get(), is((float) -100.)); assertThat(option.get(), is((float) 0)); assertThat(option.get(), is((float) 0)); assertThat(option.isNull(), is(true));
/** * 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)); }
@Override public float get(Object o) { return ((FloatOption) o).get(); } }
/** * 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)); }
/** * 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 initial state. */ @Test public void init() { FloatOption option = new FloatOption(); assertThat(option.isNull(), is(true)); }
@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/ absent value. */ @Test public void or() { FloatOption option = new FloatOption(); assertThat(option.or(30), is(30.f)); assertThat(option.isNull(), is(true)); }
@Override public int hashCode() { final int prime = 31; if (isNull()) { return 1; } int result = 1; result = prime * result + Float.floatToIntBits(result); return result; }
@Override public int compareInBytes(byte[] b1, int o1, byte[] b2, int o2) throws IOException { return compareBytes(b1, o1, b1.length - o1, b2, o2, b2.length - o2); }
FloatOption value = new FloatOption(); value.modify(+0.f); emitter.emit(value); value.modify(-0.f); emitter.emit(value); value.modify(+10.5f); emitter.emit(value); value.modify(-10.5f); emitter.emit(value); emitter.endRecord(); value.setNull(); emitter.emit(value); value.modify(Float.POSITIVE_INFINITY); emitter.emit(value); value.modify(Float.NEGATIVE_INFINITY); emitter.emit(value); value.modify(Float.NaN); emitter.emit(value); emitter.endRecord(); assertThat(parser.next(), is(true)); parser.fill(value); assertThat(value.get(), is(+0.f)); parser.fill(value); assertThat(value.get(), is(-0.f)); parser.fill(value); assertThat(value.get(), is(+10.5f));
/** * test for Writable. */ @Test public void write() { FloatOption option = new FloatOption(); option.modify(100); FloatOption restored = restore(option); assertThat(restored.get(), is(option.get())); }