TypeUtil { static public DaysSinceDate parseDaysSinceDate(LocalDate epoch, String value){ return new DaysSinceDate(epoch, parseDate(value)); } private  TypeUtil(); static String format(Object value); static Object parseOrCast(DataType dataType, Object value); static Object parse(DataType dataType, String value); static DaysSinceDate parseDaysSinceDate(LocalDate epoch, String value); static boolean equals(DataType dataType, Object value, Object referenceValue); static DataType getDataType(Object value); static DataType getDataType(Collection<?> values); static DataType getCommonDataType(DataType left, DataType right); static OpType getOpType(DataType dataType); static Object cast(DataType dataType, Object value); static V cast(Class<? extends V> clazz, Object value); static DataType getConstantDataType(Object value); static DataType getConstantDataType(String value);  }
@Test public void parseDaysSinceDate(){ DaysSinceDate sixties = (DaysSinceDate)TypeUtil.parse(DataType.DATE_DAYS_SINCE_1960, DATE); DaysSinceDate seventies = (DaysSinceDate)TypeUtil.parse(DataType.DATE_DAYS_SINCE_1970, DATE); DaysSinceDate eighties = (DaysSinceDate)TypeUtil.parse(DataType.DATE_DAYS_SINCE_1980, DATE); assertEquals(DataType.DATE_DAYS_SINCE_1960, TypeUtil.getDataType(sixties)); assertEquals(DataType.DATE_DAYS_SINCE_1970, TypeUtil.getDataType(seventies)); assertEquals(DataType.DATE_DAYS_SINCE_1980, TypeUtil.getDataType(eighties)); assertEquals(10, ChronoUnit.YEARS.between(sixties.getEpoch(), seventies.getEpoch())); assertEquals(10, ChronoUnit.YEARS.between(seventies.getEpoch(), eighties.getEpoch())); try { int diff = (sixties).compareTo(seventies); fail(); } catch(ClassCastException cce){ } assertEquals(sixties, TypeUtil.cast(DataType.DATE_DAYS_SINCE_1960, seventies)); assertEquals(sixties, TypeUtil.cast(DataType.DATE_DAYS_SINCE_1960, eighties)); assertEquals(seventies, TypeUtil.cast(DataType.DATE_DAYS_SINCE_1970, sixties)); assertEquals(seventies, TypeUtil.cast(DataType.DATE_DAYS_SINCE_1970, eighties)); assertEquals(eighties, TypeUtil.cast(DataType.DATE_DAYS_SINCE_1980, sixties)); assertEquals(eighties, TypeUtil.cast(DataType.DATE_DAYS_SINCE_1980, seventies)); assertEquals(0L, countDaysSince1960("1960-01-01")); assertEquals(1L, countDaysSince1960("1960-01-02")); assertEquals(31L, countDaysSince1960("1960-02-01")); assertEquals(-1L, countDaysSince1960("1959-12-31")); assertEquals(15796L, countDaysSince1960("2003-04-01")); }