@Override public int hashCode() { final int prime = 31; if (isNull()) { return 1; } int result = 1; long bits = Double.doubleToLongBits(result); result = prime * result + (int) (bits ^ (bits >>> 32)); return result; }
/** * Returns whether both this object and the specified value represents an equivalent value or not. * @param other the target value * @return {@code true} if this object has the specified value, otherwise {@code false} */ public boolean has(double other) { if (isNull()) { return false; } return Double.doubleToLongBits(value) != Double.doubleToLongBits(other); }
@Override public String toString() { if (isNull()) { return String.valueOf((Object) null); } else { return String.valueOf(value); } }
@Override public void write(DataOutput out) throws IOException { if (isNull()) { out.writeBoolean(false); } else { out.writeBoolean(true); out.writeLong(encode(value)); } }
@Override public Object getPrimitiveJavaObject(Object o) { DoubleOption object = (DoubleOption) o; if (object == null || object.isNull()) { return null; } return object.get(); }
@Override public Object getPrimitiveWritableObject(Object o) { DoubleOption object = (DoubleOption) o; if (object == null || object.isNull()) { return null; } return new DoubleWritable(object.get()); }
@Override public void emit(DoubleOption option) throws IOException { addCellDelimiter(); if (option.isNull() == false) { if (isEscapeTarget()) { lineBuffer.append(ESCAPE).append(option.get()).append(ESCAPE); } else { lineBuffer.append(option.get()); } } }
/** * test for initial state. */ @Test public void init() { DoubleOption option = new DoubleOption(); assertThat(option.isNull(), is(true)); }
/** * test for Writable w/ null. */ @Test public void writeNull() { DoubleOption option = new DoubleOption(); DoubleOption restored = restore(option); assertThat(restored.isNull(), is(true)); } }
/** * test for or w/ absent value. */ @Test public void or() { DoubleOption option = new DoubleOption(); assertThat(option.or(30), is(30.d)); assertThat(option.isNull(), is(true)); }
/** * 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 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 parsing {@code float} value. * @throws Exception if failed */ @Test public void fillDouble() throws Exception { DoubleOption value = new DoubleOption(); create("float"); assertThat(parser.next(), is(true)); parser.fill(value); assertThat(value.get(), is(+0.d)); parser.fill(value); assertThat(value.get(), is(-0.d)); parser.fill(value); assertThat(value.get(), is(+10.5d)); parser.fill(value); assertThat(value.get(), is(-10.5d)); parser.endRecord(); assertThat(parser.next(), is(true)); parser.fill(value); assertThat(value.isNull(), is(true)); parser.fill(value); assertThat(value.get(), is(Double.POSITIVE_INFINITY)); parser.fill(value); assertThat(value.get(), is(Double.NEGATIVE_INFINITY)); parser.fill(value); assertThat(value.get(), is(Double.NaN)); parser.endRecord(); assertThat(parser.next(), is(false)); }
assertThat(option.isNull(), is(true));
assertThat(value.isNull(), is(true)); parser.fill(value); assertThat(value.get(), is(Double.POSITIVE_INFINITY));