@SuppressWarnings("deprecation") @Override public void addInt(int value) { this.target.modify((byte) value); } }
@SuppressWarnings("deprecation") @Override protected void doRead(ValueReader reader, ByteOption property) throws IOException { int v = reader.readInt(); byte value = (byte) v; if (v != value) { throw new ArithmeticException(String.format("byte overflow: %d", v)); } property.modify(value); }
@SuppressWarnings("deprecation") @Override protected void doParseDefault(CharSequence contents, ByteOption property) { property.modify(TextUtil.parseByte(contents, 0, contents.length())); }
@SuppressWarnings("deprecation") @Override public void readFields(DataInput in) throws IOException { if (in.readBoolean()) { modify(in.readByte()); } else { setNull(); } }
@SuppressWarnings("deprecation") @Override void modify(ByteOption holder, Object value) { holder.modify(cast(Number.class, value).byteValue()); } @Override
@SuppressWarnings("deprecation") @Override protected void set(BigDecimal value, ByteOption property) { property.modify(value.byteValueExact()); }
@SuppressWarnings("deprecation") @Override public int restore(byte[] bytes, int offset, int limit) throws IOException { if (limit - offset == 0) { throw new IOException(MessageFormat.format( "Cannot restore a byte field ({0})", "invalid length")); } if (bytes[offset + 0] == 0) { setNull(); return 1; } else if (limit - offset >= 1 + 1) { modify(bytes[offset + 1]); return 2; } else { throw new IOException(MessageFormat.format( "Cannot restore a byte field ({0})", "invalid length")); } }
@SuppressWarnings("deprecation") @Override public void set(ValueOption<?> target, Object value) { if (value == null) { target.setNull(); } else { ((ByteOption) target).modify(inspector.get(value)); } }
@SuppressWarnings("deprecation") private void fill0(ByteOption option, boolean doRecover) throws CsvFormatException { if (lineBuffer.hasRemaining()) { try { byte value = Byte.parseByte(lineBuffer.toString()); option.modify(value); } catch (NumberFormatException e) { if (doRecover && trimWhitespaces()) { fill0(option, false); return; } throw new CsvFormatException(createStatusInLine(Reason.INVALID_CELL_FORMAT, "byte value"), e); } } else { option.setNull(); } }
@Override public void fill(ByteOption option) throws RecordFormatException, IOException { checkCellStart(); if (applyNull(option)) { return; } option.modify((byte) readInt(option)); fillLookAhead(); }
/** * 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 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 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)); }
/** * 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 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 Writable. */ @Test public void write_min() { ByteOption option = new ByteOption(); option.modify(Byte.MIN_VALUE); ByteOption restored = restore(option); assertThat(restored.get(), is(option.get())); }
/** * test for compare. */ @Test public void compareTo() { ByteOption a = new ByteOption(); ByteOption b = new ByteOption(); ByteOption c = new ByteOption(); ByteOption d = new ByteOption(); a.modify((byte) -10); b.modify((byte) 0); c.modify((byte) 30); d.modify((byte) -10); 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)); }
/** * 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)); }
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.modify(Byte.MAX_VALUE); emitter.emit(value); value.modify(Byte.MIN_VALUE); emitter.emit(value); emitter.endRecord();