/** * Returns whether both this object and the specified value represents an equivalent value or not. * @param other the target value * @return {@code true} if this object has the specified value, otherwise {@code false} */ public boolean has(int other) { if (isNull()) { return false; } return value == other; }
@Override public int hashCode() { final int prime = 31; if (isNull()) { return 1; } int result = 1; result = prime * result + value; return result; }
@Override public String toString() { if (isNull()) { return String.valueOf((Object) null); } else { return String.valueOf(value); } }
@Override public void write(DataOutput out) throws IOException { if (isNull()) { out.writeBoolean(false); } else { out.writeBoolean(true); out.writeShort(value); } }
@Override public Object getPrimitiveJavaObject(Object o) { ShortOption object = (ShortOption) o; if (object == null || object.isNull()) { return null; } return object.get(); }
@Override public void emit(ShortOption 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 Object getPrimitiveWritableObject(Object o) { ShortOption object = (ShortOption) o; if (object == null || object.isNull()) { return null; } return new ShortWritable(object.get()); }
/** * test for initial state. */ @Test public void init() { ShortOption option = new ShortOption(); assertThat(option.isNull(), is(true)); }
/** * test for or w/ absent value. */ @Test public void or() { ShortOption option = new ShortOption(); assertThat(option.or((short) 30), is((short) 30)); assertThat(option.isNull(), is(true)); }
/** * test for Writable w/ null. */ @Test public void writeNull() { ShortOption option = new ShortOption(); ShortOption restored = restore(option); assertThat(restored.isNull(), is(true)); } }
/** * test for get. */ @Test public void get() { ShortOption option = new ShortOption(); option.modify((short) 100); assertThat(option.get(), is((short) 100)); assertThat(option.isNull(), is(false)); }
/** * test for copyFrom w/ null. */ @Test public void copyNull() { ShortOption option = new ShortOption(); option.modify((short) 100); ShortOption other = new ShortOption(); option.copyFrom(other); assertThat(option.isNull(), is(true)); option.modify((short) 100); option.copyFrom(null); assertThat(option.isNull(), is(true)); }
/** * test for parsing {@code short} value. * @throws Exception if failed */ @Test public void fillShort() throws Exception { ShortOption value = new ShortOption(); create("short"); assertThat(parser.next(), is(true)); parser.fill(value); assertThat(value.get(), is((short) 0)); parser.fill(value); assertThat(value.get(), is((short) 10)); parser.fill(value); assertThat(value.get(), is((short) -10)); parser.endRecord(); assertThat(parser.next(), is(true)); parser.fill(value); assertThat(value.isNull(), is(true)); parser.fill(value); assertThat(value.get(), is(Short.MAX_VALUE)); parser.fill(value); assertThat(value.get(), is(Short.MIN_VALUE)); parser.endRecord(); assertThat(parser.next(), is(false)); }
assertThat(option.isNull(), is(true));
assertThat(value.isNull(), is(true)); parser.fill(value); assertThat(value.get(), is(Short.MAX_VALUE));