@Test public void nullTest() { Integer year = null; Integer month = null; Integer day = null; Optional<Temporal> temporal = TemporalUtils.getTemporal(year, month, day); assertFalse(temporal.isPresent()); }
public static Optional<Temporal> getTemporal(Integer year, Integer month, Integer day) { try { if (year != null && month != null && day != null) { return Optional.of(LocalDate.of(year, month, day)); } if (year != null && month != null) { return Optional.of(YearMonth.of(year, month)); } if (year != null) { return Optional.of(Year.of(year)); } } catch (RuntimeException ex) { log.warn(ex.getLocalizedMessage()); } return Optional.empty(); }
TemporalUtils { public static Optional<Temporal> getTemporal(Integer year, Integer month, Integer day) { try { if (year != null && month != null && day != null) { return Optional.of(LocalDate.of(year, month, day)); } if (year != null && month != null) { return Optional.of(YearMonth.of(year, month)); } if (year != null) { return Optional.of(Year.of(year)); } } catch (RuntimeException ex) { log.warn(ex.getLocalizedMessage()); } return Optional.empty(); } }
TemporalUtils { public static Optional<Temporal> getTemporal(Integer year, Integer month, Integer day) { try { if (year != null && month != null && day != null) { return Optional.of(LocalDate.of(year, month, day)); } if (year != null && month != null) { return Optional.of(YearMonth.of(year, month)); } if (year != null) { return Optional.of(Year.of(year)); } } catch (RuntimeException ex) { log.warn(ex.getLocalizedMessage()); } return Optional.empty(); }  }
TemporalUtils { public static Optional<Temporal> getTemporal(Integer year, Integer month, Integer day) { try { if (year != null && month != null && day != null) { return Optional.of(LocalDate.of(year, month, day)); } if (year != null && month != null) { return Optional.of(YearMonth.of(year, month)); } if (year != null) { return Optional.of(Year.of(year)); } } catch (RuntimeException ex) { log.warn(ex.getLocalizedMessage()); } return Optional.empty(); }  static Optional<Temporal> getTemporal(Integer year, Integer month, Integer day); }
TemporalUtils { public static Optional<Temporal> getTemporal(Integer year, Integer month, Integer day) { try { if (year != null && month != null && day != null) { return Optional.of(LocalDate.of(year, month, day)); } if (year != null && month != null) { return Optional.of(YearMonth.of(year, month)); } if (year != null) { return Optional.of(Year.of(year)); } } catch (RuntimeException ex) { log.warn(ex.getLocalizedMessage()); } return Optional.empty(); }  static Optional<Temporal> getTemporal(Integer year, Integer month, Integer day);  }