Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalQuery;

public class Main {

    public static void main(String[] args) {
        LocalDate ld1 = LocalDate.of(2013, 12, 1);
        Boolean is = ld1.query(new Monday1Query());
        System.out.println(is);

    }
}

class Monday1Query implements TemporalQuery<Boolean> {
    @Override
    public Boolean queryFrom(TemporalAccessor temporal) {
        if (temporal.isSupported(ChronoField.DAY_OF_MONTH) && temporal.isSupported(ChronoField.DAY_OF_WEEK)) {
            int dayOfMonth = temporal.get(ChronoField.DAY_OF_MONTH);
            int weekDay = temporal.get(ChronoField.DAY_OF_WEEK);
            DayOfWeek dayOfWeek = DayOfWeek.of(weekDay);
            if (dayOfMonth == 1 && dayOfWeek == DayOfWeek.MONDAY) {
                return Boolean.TRUE;
            }
        }
        return Boolean.FALSE;
    }
}