@SuppressWarnings("deprecation") @Override public void addInt(int value) { this.target.modify((byte) value); } }
@Override protected ValueOption<?> newObject() { return new ByteOption(); }
/** * test for get. */ @Test public void get() { ByteOption option = new ByteOption(); option.modify((byte) 100); assertThat(option.get(), is((byte) 100)); assertThat(option.isNull(), is(false)); }
/** * test for Writable. */ @Test public void write_max() { ByteOption option = new ByteOption(); option.modify(Byte.MAX_VALUE); ByteOption restored = restore(option); assertThat(restored.get(), is(option.get())); }
/** * test for copyFrom. */ @Test public void copy() { ByteOption option = new ByteOption(); ByteOption other = new ByteOption(); other.modify((byte) 50); option.copyFrom(other); assertThat(option.get(), is((byte) 50)); option.modify((byte) 0); assertThat(other.get(), is((byte) 50)); }
public void byte_values() throws Exception { CsvParser parser = create("0,1,50,-1,-50,127,-128, 0,0 ,"); ByteOption option = new ByteOption(); assertThat(option.get(), is((byte) 0)); assertThat(option.get(), is((byte) 1)); assertThat(option.get(), is((byte) 50)); assertThat(option.get(), is((byte) -1)); assertThat(option.get(), is((byte) -50)); assertThat(option.get(), is((byte) 127)); assertThat(option.get(), is((byte) -128)); assertThat(option.get(), is((byte) 0)); assertThat(option.get(), is((byte) 0)); assertThat(option.isNull(), is(true));
/** * test for copyFrom w/ null. */ @Test public void copyNull() { ByteOption option = new ByteOption(); option.modify((byte) 100); ByteOption other = new ByteOption(); option.copyFrom(other); assertThat(option.isNull(), is(true)); option.modify((byte) 100); option.copyFrom(null); assertThat(option.isNull(), is(true)); }
@Override public byte get(Object o) { return ((ByteOption) o).get(); } }
/** * test for compare w/ null. */ @Test public void compareNull() { ByteOption a = new ByteOption(); ByteOption b = new ByteOption(); ByteOption c = new ByteOption(); a.modify((byte) 0x80); assertThat(compare(a, b), greaterThan(0)); assertThat(compare(b, a), lessThan(0)); assertThat(compare(b, c), is(0)); }
/** * test for or. */ @Test public void orNotNull() { ByteOption option = new ByteOption(); option.modify((byte) 100); assertThat(option.or((byte) 30), is((byte) 100)); }
/** * test for initial state. */ @Test public void init() { ByteOption option = new ByteOption(); assertThat(option.isNull(), is(true)); }
/** * test for or w/ null. */ @Test public void or() { ByteOption option = new ByteOption(); assertThat(option.or((byte) 30), is((byte) 30)); assertThat(option.isNull(), is(true)); }
@Override public int hashCode() { final int prime = 31; if (isNull()) { return 1; } int result = 1; result = prime * result + value; 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); }
ByteOption value = new ByteOption(); value.modify((byte) 0); emitter.emit(value); value.modify((byte) 10); emitter.emit(value); value.modify((byte) -10); emitter.emit(value); emitter.endRecord(); value.setNull(); emitter.emit(value); value.modify(Byte.MAX_VALUE); emitter.emit(value); value.modify(Byte.MIN_VALUE); emitter.emit(value); emitter.endRecord(); assertThat(parser.next(), is(true)); parser.fill(value); assertThat(value.get(), is((byte) 0)); parser.fill(value); assertThat(value.get(), is((byte) 10)); parser.fill(value); assertThat(value.get(), is((byte) -10)); assertThat(value.isNull(), is(true)); parser.fill(value); assertThat(value.get(), is(Byte.MAX_VALUE));
/** * test for Writable. */ @Test public void write() { ByteOption option = new ByteOption(); option.modify((byte) 100); ByteOption restored = restore(option); assertThat(restored.get(), is(option.get())); }
/** * test for parsing {@code byte} value. * @throws Exception if failed */ @Test public void fillByte() throws Exception { ByteOption value = new ByteOption(); create("byte"); assertThat(parser.next(), is(true)); parser.fill(value); assertThat(value.get(), is((byte) 0)); parser.fill(value); assertThat(value.get(), is((byte) 10)); parser.fill(value); assertThat(value.get(), is((byte) -10)); parser.endRecord(); assertThat(parser.next(), is(true)); parser.fill(value); assertThat(value.isNull(), is(true)); parser.fill(value); assertThat(value.get(), is(Byte.MAX_VALUE)); parser.fill(value); assertThat(value.get(), is(Byte.MIN_VALUE)); parser.endRecord(); assertThat(parser.next(), is(false)); }
@Override Object extract(ByteOption holder) { return holder.get(); } });