IF arraylist x在switch方法中包含y语句

时间:2016-09-06 16:02:30

标签: java arraylist

我的代码的目的是输出一个新的文件夹名称,其中包含与前一个工作日相关的数字标识符和日期戳。我正在努力使用代码来确定上一个工作日。周末被正确地考虑在内,但是我似乎无法正确地构造if语句以考虑帐户假期。我已经包含了我认为相关的所有代码。

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;

    }
}

netbeans在尝试运行时产生的错误是:

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)

0 个答案:

没有答案