@Override Object extract(LongOption holder) { return holder.get(); } });
@SuppressWarnings("deprecation") @Override public void addLong(long value) { this.target.modify(value); } }
@Override protected ValueOption<?> newObject() { return new LongOption(); }
/** * test for get. */ @Test public void get() { LongOption option = new LongOption(); option.modify(100); assertThat(option.get(), is(100L)); assertThat(option.isNull(), is(false)); }
/** * test for Writable. */ @Test public void write() { LongOption option = new LongOption(); option.modify(100); LongOption restored = restore(option); assertThat(restored.get(), is(option.get())); }
/** * test for copyFrom. */ @Test public void copy() { LongOption option = new LongOption(); LongOption other = new LongOption(); other.modify(50); option.copyFrom(other); assertThat(option.get(), is(50L)); option.modify(0); assertThat(other.get(), is(50L)); }
/** * test for compare w/ null. */ @Test public void compareNull() { LongOption a = new LongOption(); LongOption b = new LongOption(); LongOption c = new LongOption(); a.modify(Long.MIN_VALUE); assertThat(compare(a, b), greaterThan(0)); assertThat(compare(b, a), lessThan(0)); assertThat(compare(b, c), is(0)); }
/** * test for copyFrom w/ null. */ @Test public void copyNull() { LongOption option = new LongOption(); option.modify(100); LongOption other = new LongOption(); option.copyFrom(other); assertThat(option.isNull(), is(true)); option.modify(100); option.copyFrom(null); assertThat(option.isNull(), is(true)); }
/** * test for parsing {@code long} value. * @throws Exception if failed */ @Test public void fillLong() throws Exception { LongOption value = new LongOption(); create("long"); assertThat(parser.next(), is(true)); parser.fill(value); assertThat(value.get(), is(0L)); parser.fill(value); assertThat(value.get(), is(10L)); parser.fill(value); assertThat(value.get(), is(-10L)); parser.endRecord(); assertThat(parser.next(), is(true)); parser.fill(value); assertThat(value.isNull(), is(true)); parser.fill(value); assertThat(value.get(), is(Long.MAX_VALUE)); parser.fill(value); assertThat(value.get(), is(Long.MIN_VALUE)); parser.endRecord(); assertThat(parser.next(), is(false)); }
/** * test for or w/ present value. */ @Test public void orNotNull() { LongOption option = new LongOption(); option.modify(100); assertThat(option.or(30), is(100L)); }
/** * test for initial state. */ @Test public void init() { LongOption option = new LongOption(); assertThat(option.isNull(), is(true)); }
/** * test for or w/ absent value. */ @Test public void or() { LongOption option = new LongOption(); assertThat(option.or(30), is(30L)); assertThat(option.isNull(), is(true)); }
@Override public int hashCode() { final int prime = 31; if (isNull()) { return 1; } int result = 1; result = prime * result + (int) (value ^ (value >>> 32)); return result; }
/** * Sets amount_total. * @param option the value, or <code>null</code> to set this property to <code>null</code> */ @SuppressWarnings("deprecation") public void setAmountTotalOption(LongOption option) { this.amountTotal.copyFrom(option); } /**
LongOption value = new LongOption(); value.modify(0L); emitter.emit(value); value.modify(10L); emitter.emit(value); value.modify(-10L); emitter.emit(value); emitter.endRecord(); value.setNull(); emitter.emit(value); value.modify(Long.MAX_VALUE); emitter.emit(value); value.modify(Long.MIN_VALUE); emitter.emit(value); emitter.endRecord(); assertThat(parser.next(), is(true)); parser.fill(value); assertThat(value.get(), is(0L)); parser.fill(value); assertThat(value.get(), is(10L)); parser.fill(value); assertThat(value.get(), is(-10L)); assertThat(value.isNull(), is(true)); parser.fill(value); assertThat(value.get(), is(Long.MAX_VALUE));
/** * test for Writable w/ max. */ @Test public void write_max() { LongOption option = new LongOption(); option.modify(Long.MAX_VALUE); LongOption restored = restore(option); assertThat(restored.get(), is(option.get())); }
/** * test for compare. */ @Test public void compareTo() { LongOption a = new LongOption(); LongOption b = new LongOption(); LongOption c = new LongOption(); LongOption d = new LongOption(); a.modify(Long.MIN_VALUE); b.modify(0); c.modify(50); d.modify(Long.MIN_VALUE); 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)); }