The aim of my code is to output a new folder name containing a numerical identifier and date stamp relevant to the previous working day. I am struggling with the code to identify the previous working day. Weekends are correctly taken into account, however i cannot seem to structure the if statement correctly to take into accounts holidays as well. I have included all code i thought was relevant.
LocalDate xDay;
List<LocalDate> holidays = Arrays.asList((LocalDate.of(2016, 3, 25)),
(LocalDate.of(2016, 3, 28)),
(LocalDate.of(2016, 5, 2)),
(LocalDate.of(2016, 5, 30)),
(LocalDate.of(2016, 8, 29)),
//test(LocalDate.of(2016, 9, 5)),
(LocalDate.of(2016, 12, 26)),
(LocalDate.of(2016, 12, 27)));
LocalDate getPreviousWorkingDay(LocalDate date) {
DayOfWeek dayOfWeek = DayOfWeek.of(date.get(ChronoField.DAY_OF_WEEK));
xDay = (date.minus(1, ChronoUnit.DAYS));
switch (dayOfWeek) {
case MONDAY:
return date.minus(3, ChronoUnit.DAYS);
case SUNDAY:
return date.minus(2, ChronoUnit.DAYS);
case TUESDAY:
if (holidays.contains(xDay)== true){
return date.minus(4, ChronoUnit.DAYS);
}
else {
return xDay;
}
default:
return xDay;
}
}
The error produced by netbeans when trying to run is :
Exception in thread "main" java.lang.NullPointerException
at watchdoxgenerator.DisWatchdoxClean$WatchdoxClean.getPreviousWorkingDay(DisWatchdoxClean.java:94)
at watchdoxgenerator.DisWatchdoxClean$WatchdoxClean.<init>(DisWatchdoxClean.java:32)
at watchdoxgenerator.DisWatchdoxClean.main(DisWatchdoxClean.java:127)