/** * Returns whether both this object and the specified value represents an equivalent value or not. * @param other the target value (nullable) * @return {@code true} if this object has the specified value, otherwise {@code false} */ public boolean has(BigDecimal other) { if (isNull()) { return other == null; } return entity.equals(other); }
@Override public int hashCode() { final int prime = 31; if (isNull()) { return 1; } int result = 1; result = prime * result + entity.hashCode(); return result; }
@Override public String toString() { if (isNull()) { return String.valueOf((Object) null); } else { return get().toString(); } }
@Override public void emit(DecimalOption option) throws IOException { addCellDelimiter(); if (option.isNull() == false) { if (isEscapeTarget()) { lineBuffer.append(ESCAPE).append(option.get()).append(ESCAPE); } else { lineBuffer.append(option.get()); } } }
@Override public HiveDecimal getPrimitiveJavaObject(Object o) { DecimalOption object = (DecimalOption) o; if (object == null || object.isNull()) { return null; } return convert(object.get()); }
/** * test for initial state. */ @Test public void init() { DecimalOption option = new DecimalOption(); assertThat(option.isNull(), is(true)); }
/** * test for Writable w/ null. */ @Test public void writeNull() { DecimalOption option = new DecimalOption(); DecimalOption restored = restore(option); assertThat(restored.isNull(), is(true)); }
/** * test for or w/ null. */ @Test public void or() { DecimalOption option = new DecimalOption(); assertThat(option.or(decimal(30)), is(decimal(30))); assertThat(option.isNull(), is(true)); }
/** * test for copyFrom w/ null. */ @Test public void copyNull() { DecimalOption option = new DecimalOption(); option.modify(decimal(100)); DecimalOption other = new DecimalOption(); option.copyFrom(other); assertThat(option.isNull(), is(true)); option.modify(decimal(100)); option.copyFrom(null); assertThat(option.isNull(), is(true)); }
/** * test for get. */ @Test public void get() { DecimalOption option = new DecimalOption(); option.modify(decimal(100)); assertThat(option.get(), is(decimal(100))); assertThat(option.isNull(), is(false)); }
/** * test for parsing {@code decimal} value. * @throws Exception if failed */ @Test public void fillDecimal() throws Exception { DecimalOption value = new DecimalOption(); create("decimal"); assertThat(parser.next(), is(true)); parser.fill(value); assertThat(value.get(), is(decimal("0"))); parser.fill(value); assertThat(value.get(), is(decimal("10"))); parser.fill(value); assertThat(value.get(), is(decimal("-10"))); parser.endRecord(); assertThat(parser.next(), is(true)); parser.fill(value); assertThat(value.isNull(), is(true)); parser.fill(value); assertThat(value.get(), is(decimal("0.9999999999999999999999999999999999999999999999999"))); parser.fill(value); assertThat(value.get(), is(decimal("9223372036854775809"))); parser.endRecord(); assertThat(parser.next(), is(false)); }
assertThat(value.isNull(), is(true)); parser.fill(value); assertThat(value.get(), is(decimal("0.9999999999999999999999999999999999999999999999999")));