@Test public void testToDateTime() { assertEquals(Date.from(now), toTimeType(now, Date.class)); assertEquals(Date.from(now), toTimeType(now.toEpochMilli(), Date.class)); }
@SuppressWarnings("unchecked") public static <T> T toTimeType(Object timeValue, Class<T> targetTimeType) { Class valueClass = timeValue.getClass(); Function<Object, Object> timeConverter = TIME_CONVERTERS.get(new Pair(valueClass, targetTimeType)); if (timeConverter == null) { throw Element.Exceptions.invalidTimeType(targetTimeType, timeValue); } return (T) timeConverter.apply(timeValue); }
Primitives { @SuppressWarnings("unchecked") public static <T> T toTimeType(Object timeValue, Class<T> targetTimeType) { Class valueClass = timeValue.getClass(); Function<Object, Object> timeConverter = TIME_CONVERTERS.get(new Pair(valueClass, targetTimeType)); if (timeConverter == null) { throw Element.Exceptions.invalidTimeType(targetTimeType, timeValue); } return (T) timeConverter.apply(timeValue); } }
Primitives { @SuppressWarnings("unchecked") public static <T> T toTimeType(Object timeValue, Class<T> targetTimeType) { Class valueClass = timeValue.getClass(); Function<Object, Object> timeConverter = TIME_CONVERTERS.get(new Pair(valueClass, targetTimeType)); if (timeConverter == null) { throw Element.Exceptions.invalidTimeType(targetTimeType, timeValue); } return (T) timeConverter.apply(timeValue); } private  Primitives(); }
Primitives { @SuppressWarnings("unchecked") public static <T> T toTimeType(Object timeValue, Class<T> targetTimeType) { Class valueClass = timeValue.getClass(); Function<Object, Object> timeConverter = TIME_CONVERTERS.get(new Pair(valueClass, targetTimeType)); if (timeConverter == null) { throw Element.Exceptions.invalidTimeType(targetTimeType, timeValue); } return (T) timeConverter.apply(timeValue); } private  Primitives(); static void registerPrimitiveClass(Class primitiveClass); @SneakyThrows static void registerPrimitiveClass(Class primitiveClass, Object primitiveDefault); @SuppressWarnings("unchecked") static void registerStringConverters(Class<P> primitiveClass,
      Function<String, P> stringConverter); @SuppressWarnings("unchecked") static void registerTimeConverters(Class sourceTimeClass, Class targetTimeClass,
      Function<Object, Object> timeConverter); static boolean isPrimitive(Field field); static boolean isPrimitive(Class clazz); static boolean isPrimitiveDefault(Field field, Object value); static Object asPrimitiveType(Field field, String defaultValue); static boolean isMissing(Object object); static boolean isTimeType(Class clazz); static Date toDate(long epoch); static Date toDate(long epoch, TimeUnit timeUnit); static long toEpoch(Date date); static Instant toInstant(long epoch); static long toEpoch(Instant instant); static Instant toInstant(Date date); static Date toDate(Instant instant); @SuppressWarnings("unchecked") static T toTimeType(Object timeValue, Class<T> targetTimeType); }
Primitives { @SuppressWarnings("unchecked") public static <T> T toTimeType(Object timeValue, Class<T> targetTimeType) { Class valueClass = timeValue.getClass(); Function<Object, Object> timeConverter = TIME_CONVERTERS.get(new Pair(valueClass, targetTimeType)); if (timeConverter == null) { throw Element.Exceptions.invalidTimeType(targetTimeType, timeValue); } return (T) timeConverter.apply(timeValue); } private  Primitives(); static void registerPrimitiveClass(Class primitiveClass); @SneakyThrows static void registerPrimitiveClass(Class primitiveClass, Object primitiveDefault); @SuppressWarnings("unchecked") static void registerStringConverters(Class<P> primitiveClass,
      Function<String, P> stringConverter); @SuppressWarnings("unchecked") static void registerTimeConverters(Class sourceTimeClass, Class targetTimeClass,
      Function<Object, Object> timeConverter); static boolean isPrimitive(Field field); static boolean isPrimitive(Class clazz); static boolean isPrimitiveDefault(Field field, Object value); static Object asPrimitiveType(Field field, String defaultValue); static boolean isMissing(Object object); static boolean isTimeType(Class clazz); static Date toDate(long epoch); static Date toDate(long epoch, TimeUnit timeUnit); static long toEpoch(Date date); static Instant toInstant(long epoch); static long toEpoch(Instant instant); static Instant toInstant(Date date); static Date toDate(Instant instant); @SuppressWarnings("unchecked") static T toTimeType(Object timeValue, Class<T> targetTimeType); static boolean allowDefaultKeys; }