@SuppressWarnings("deprecation") @Override public void addBoolean(boolean value) { this.target.modify(value); } }
@Override protected ValueOption<?> newObject() { return new BooleanOption(); }
@SuppressWarnings("deprecation") private void restore(byte field) throws IOException { if (field == SERIALIZE_NULL) { setNull(); } else if (field == SERIALIZE_TRUE) { modify(true); } else if (field == SERIALIZE_FALSE) { modify(false); } else { throw new IOException(MessageFormat.format( "Cannot restore a boolean field ({0})", field)); } }
/** * obtain value. */ @Test public void get() { BooleanOption option = new BooleanOption(); option.modify(false); assertThat(option.get(), is(false)); assertThat(option.isNull(), is(false)); }
/** * test for Writable. */ @Test public void writeTrue() { BooleanOption option = new BooleanOption(); option.modify(true); BooleanOption restored = restore(option); assertThat(restored.get(), is(option.get())); }
/** * test for copyFrom. */ @Test public void copy() { BooleanOption option = new BooleanOption(); BooleanOption other = new BooleanOption(); other.modify(true); option.copyFrom(other); assertThat(option.get(), is(true)); option.modify(false); assertThat(other.get(), is(true)); }
/** * test for booleans. * @throws Exception if failed */ @Test public void boolean_values() throws Exception { trueFormat = "true"; falseFormat = "false"; CsvParser parser = create("true,false,"); BooleanOption option = new BooleanOption(); assertThat(parser.next(), is(true)); parser.fill(option); assertThat(option.get(), is(true)); parser.fill(option); assertThat(option.get(), is(false)); parser.fill(option); assertThat(option.isNull(), is(true)); parser.endRecord(); assertThat(parser.next(), is(false)); }
/** * test for copyFrom w/ null. */ @Test public void copyNull() { BooleanOption option = new BooleanOption(); option.modify(true); BooleanOption other = new BooleanOption(); option.copyFrom(other); assertThat(option.isNull(), is(true)); option.modify(true); option.copyFrom(null); assertThat(option.isNull(), is(true)); }
@Override Object extract(BooleanOption holder) { return holder.get(); } });
/** * test for compare. */ @Test public void compareTo() { BooleanOption a = new BooleanOption(); BooleanOption b = new BooleanOption(); BooleanOption c = new BooleanOption(); a.modify(false); b.modify(true); c.modify(false); assertThat(compare(a, b), lessThan(0)); assertThat(compare(b, a), greaterThan(0)); assertThat(compare(a, c), is(0)); }
/** * test for or. */ @Test public void orNotNull() { BooleanOption option = new BooleanOption(); option.modify(true); assertThat(option.or(false), is(true)); }
/** * test for initial state. */ @Test public void init() { BooleanOption option = new BooleanOption(); assertThat(option.isNull(), is(true)); }
/** * test for or w/ null. */ @Test public void or() { BooleanOption option = new BooleanOption(); assertThat(option.or(true), is(true)); assertThat(option.isNull(), is(true)); }
@Override public int hashCode() { final int prime = 31; if (isNull()) { return 1; } int result = 1; result = prime * result + (value ? TRUE_HASHCODE : FALSE_HASHCODE); 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); }
BooleanOption value = new BooleanOption(); value.modify(true); emitter.emit(value); value.modify(false); emitter.emit(value); emitter.endRecord(); value.modify(false); emitter.emit(value); value.modify(true); emitter.emit(value); emitter.endRecord(); value.setNull(); emitter.emit(value); value.modify(true); emitter.emit(value); emitter.endRecord(); assertThat(parser.next(), is(true)); parser.fill(value); assertThat(value.get(), is(true)); parser.fill(value); assertThat(value.get(), is(false)); assertThat(value.get(), is(false)); parser.fill(value); assertThat(value.get(), is(true));
/** * test for Writable. */ @Test public void writeFalse() { BooleanOption option = new BooleanOption(); option.modify(true); BooleanOption restored = restore(option); assertThat(restored.get(), is(option.get())); }
/** * test for parsing {@code boolean} value. * @throws Exception if failed */ @Test public void fillBoolean() throws Exception { BooleanOption value = new BooleanOption(); create("boolean"); assertThat(parser.next(), is(true)); parser.fill(value); assertThat(value.get(), is(true)); parser.fill(value); assertThat(value.get(), is(false)); parser.endRecord(); assertThat(parser.next(), is(true)); parser.fill(value); assertThat(value.get(), is(false)); parser.fill(value); assertThat(value.get(), is(true)); parser.endRecord(); assertThat(parser.next(), is(true)); parser.fill(value); assertThat(value.isNull(), is(true)); parser.fill(value); assertThat(value.isNull(), is(false)); parser.endRecord(); }
@Override public boolean get(Object o) { return ((BooleanOption) o).get(); } }