EncodingSchemeUtils { public static Temporal decodeTemporal(DublinCoreValue value) { Date instant = decodeDate(value); if (instant != null) return Temporal.instant(instant); DCMIPeriod period = decodePeriod(value); if (period != null) return Temporal.period(period); Long duration = decodeDuration(value); if (duration != null) return Temporal.duration(duration); return null; } private  EncodingSchemeUtils(); static DublinCoreValue encodeDate(Date date, Precision precision); static String formatDate(Date date, Precision precision); static DublinCoreValue encodePeriod(DCMIPeriod period, Precision precision); static DublinCoreValue encodeDuration(long duration); static Long decodeDuration(String value); static Long decodeDuration(DublinCoreValue value); static Long decodeMandatoryDuration(String value); static Date decodeDate(DublinCoreValue value); static Date decodeDate(String value); static Date decodeMandatoryDate(DublinCoreValue value); static Date decodeMandatoryDate(String value); static DCMIPeriod decodePeriod(DublinCoreValue value); static DCMIPeriod decodePeriod(String value); static DCMIPeriod decodeMandatoryPeriod(DublinCoreValue value); static DCMIPeriod decodeMandatoryPeriod(String value); static Temporal decodeTemporal(DublinCoreValue value); static Temporal decodeMandatoryTemporal(DublinCoreValue value);  }
@Test public void testDecodeTemporal() { Temporal.Match<Integer> match = new Temporal.Match<Integer>() { @Override public Integer period(DCMIPeriod period) { return 1; } @Override public Integer instant(Date instant) { return 2; } @Override public Integer duration(long duration) { return 3; } }; Temporal.Match<Long> durationMatch = new Temporal.Match<Long>() { @Override public Long period(DCMIPeriod period) { throw new RuntimeException(); } @Override public Long instant(Date instant) { throw new RuntimeException(); } @Override public Long duration(long duration) { return duration; } }; assertSame(1, decodeTemporal(DublinCoreValue.mk("start=2008-10-01; end=2009-01-01;")).fold(match)); assertSame(2, decodeTemporal(DublinCoreValue.mk("2008-10-01")).fold(match)); assertSame(2, decodeTemporal(DublinCoreValue.mk("2008-10-01T10:30:05Z")).fold(match)); assertSame(1, decodeTemporal(DublinCoreValue.mk("start=2008-10-01T10:20Z; end=2009-01-01; scheme=W3C-DTF")).fold(match)); assertSame(3, decodeTemporal(DublinCoreValue.mk("PT10H5M")).fold(match)); assertEquals(10L * 60 * 60 * 1000 + 5 * 60 * 1000, (long) decodeTemporal(DublinCoreValue.mk("PT10H5M")).fold(durationMatch)); assertEquals(10L * 60 * 60 * 1000 + 5 * 60 * 1000 + 28 * 1000, (long) decodeTemporal(DublinCoreValue.mk("PT10H5M28S")).fold(durationMatch)); }