/** * Returns whether both this object and the specified value represents an equivalent value or not. * @param other the target value (nullable) * @return {@code true} if this object has the specified value, otherwise {@code false} */ public boolean has(DateTime other) { if (isNull()) { return other == null; } return entity.equals(other); }
@Override public int hashCode() { final int prime = 31; if (isNull()) { return 1; } int result = 1; result = prime * result + entity.hashCode(); return result; }
@Override public void write(DataOutput out) throws IOException { if (isNull()) { out.writeBoolean(false); } else { out.writeBoolean(true); out.writeLong(entity.getElapsedSeconds()); } }
@Override public String toString() { if (isNull()) { return String.valueOf((Object) null); } else { return get().toString(); } }
@Override public void emit(DateTimeOption option) throws IOException { addCellDelimiter(); if (option.isNull() == false) { CharSequence string = dateTimeFormat.format(option.get().getElapsedSeconds()); if (escapeDateTime || isEscapeTarget()) { appendEscaped(lineBuffer, string); } else { lineBuffer.append(string); } } }
@Override public java.sql.Timestamp getPrimitiveJavaObject(Object o) { DateTimeOption object = (DateTimeOption) o; if (object == null || object.isNull()) { return null; } DateTime value = object.get(); // FIXME for optimization @SuppressWarnings("deprecation") java.sql.Timestamp result = new java.sql.Timestamp( value.getYear() - 1900, value.getMonth() - 1, value.getDay(), value.getHour(), value.getMinute(), value.getSecond(), 0); return result; }
/** * test for initial state. */ @Test public void init() { DateTimeOption option = new DateTimeOption(); assertThat(option.isNull(), is(true)); }
/** * test for Writable w/ null. */ @Test public void writableOption() { DateTimeOption option = new DateTimeOption(); DateTimeOption restored = restore(option); assertThat(restored.isNull(), is(true)); }
/** * test for copyFrom w/ null. */ @Test public void copyNull() { DateTimeOption option = new DateTimeOption(); option.modify(time(100)); DateTimeOption other = new DateTimeOption(); option.copyFrom(other); assertThat(option.isNull(), is(true)); option.modify(time(200)); assertThat(option.isNull(), is(false)); option.copyFrom(null); assertThat(option.isNull(), is(true)); }
/** * test for or w/ int. */ @Test public void intOr() { DateTimeOption option = new DateTimeOption(); assertThat(option.or(100), is(100L)); assertThat(option.isNull(), is(true)); option.modify(200); assertThat(option.or(300), is(200L)); }
/** * test for set elapsed seconds. */ @Test public void setLong() { DateTimeOption option = new DateTimeOption(); option.modify(500); assertThat(option.isNull(), is(false)); assertThat(option.get(), is(time(500))); }
/** * test for date-time type. */ @Test public void string() { DateTimeOption option = new DateTimeOption(); option.modify(time(999)); assertThat(option.isNull(), is(false)); assertThat(option.get(), is(time(999))); }
/** * test for or w/ date-time type. */ @Test public void stringOr() { DateTimeOption option = new DateTimeOption(); assertThat(option.or(time(200)), is(time(200))); assertThat(option.isNull(), is(true)); option.modify(time(300)); assertThat(option.or(time(400)), is(time(300))); }
/** * test for date-time values. * @throws Exception if failed */ @Test public void datetime_values() throws Exception { dateTimeFormat = "yyyy/MM/dd HH:mm:ss"; CsvParser parser = create( "2011/03/31 23:59:59," + "1971/4/1 1:2:3," + " 1971/4/1 1:2:3 ,"); DateTimeOption option = new DateTimeOption(); assertThat(parser.next(), is(true)); parser.fill(option); assertThat(option.get(), is(new DateTime(2011, 3, 31, 23, 59, 59))); parser.fill(option); assertThat(option.get(), is(new DateTime(1971, 4, 1, 1, 2, 3))); parser.fill(option); assertThat(option.get(), is(new DateTime(1971, 4, 1, 1, 2, 3))); parser.fill(option); assertThat(option.isNull(), is(true)); parser.endRecord(); assertThat(parser.next(), is(false)); }
/** * test for date-time values. * @throws Exception if failed */ @Test public void datetime_values_direct() throws Exception { dateTimeFormat = "yyyyMMddHHmmss"; CsvParser parser = create( "20110331235959," + "19710401010203," + " 19710401010203 ,"); DateTimeOption option = new DateTimeOption(); assertThat(parser.next(), is(true)); parser.fill(option); assertThat(option.get(), is(new DateTime(2011, 3, 31, 23, 59, 59))); parser.fill(option); assertThat(option.get(), is(new DateTime(1971, 4, 1, 1, 2, 3))); parser.fill(option); assertThat(option.get(), is(new DateTime(1971, 4, 1, 1, 2, 3))); parser.fill(option); assertThat(option.isNull(), is(true)); parser.endRecord(); assertThat(parser.next(), is(false)); }
assertThat(value.isNull(), is(true)); parser.fill(value); assertThat(value.get(), is(time(1, 1, 1, 0, 0, 0)));