@@ -0,0 +1,2136 @@
+package com.levelup.java.date.query;%0A%0Aimport static org.junit.Assert.assertFalse;%0Aimport static org.junit.Assert.assertTrue;%0A%0Aimport java.time.LocalDate;%0Aimport java.time.Month;%0Aimport java.time.MonthDay;%0Aimport java.time.temporal.TemporalAccessor;%0Aimport java.time.temporal.TemporalQuery;%0Aimport java.util.List;%0A%0Aimport org.junit.Test;%0A%0Aimport com.google.common.collect.Lists;%0A%0A/**%0A * This java example will demonstrate checking to %0A * see if a date or temporal object is a company holiday.%0A * %0A * @author Justin Musgrove%0A * @see %3Ca href='http://www.leveluplunch.com/java/examples/company-holiday-temporal-query-java8/'%3ECompany holiday query%3C/a%3E%0A */%0Apublic class CompanyHolidayQuery implements TemporalQuery%3CBoolean%3E %7B%0A%09%0A%09static List%3CMonthDay%3E COMPANY_HOLIDAYS = Lists.newArrayList(%0A%09%09%09MonthDay.of(Month.JANUARY, 1), // New Years Day%09January 1%0A%09%09%09MonthDay.of(Month.JANUARY, 20), // Martin Luther King, Jr. Day%09January 20%0A%09%09%09MonthDay.of(Month.APRIL, 18), // Good Friday%09April 18%0A%09%09%09MonthDay.of(Month.MAY, 26), // Memorial Day%09May 26%0A%09%09%09MonthDay.of(Month.JULY, 4), // Independence Day%09July 4**%0A%09%09%09MonthDay.of(Month.SEPTEMBER, 1), // Labor Day%09September 1%0A%09%09%09MonthDay.of(Month.NOVEMBER, 27), // Thanksgiving Day%09November 27*%0A%09%09%09MonthDay.of(Month.NOVEMBER, 28), // Day after thanksgiving November 28*%0A%09%09%09MonthDay.of(Month.DECEMBER, 25), // Christmas%09December 25***%0A%09%09%09MonthDay.of(Month.DECEMBER, 26) // Day after xmas%09December 26***%0A%09);%0A%09%0A%09/* (non-Javadoc)%0A%09 * @see java.time.temporal.TemporalQuery#queryFrom(java.time.temporal.TemporalAccessor)%0A%09 */%0A%09@Override%0A%09public Boolean queryFrom(TemporalAccessor date) %7B%0A%0A%09%09MonthDay currentMonthDay = MonthDay.from(date);%0A%09%09%0A%09%09return COMPANY_HOLIDAYS.contains(currentMonthDay);%0A%09%7D%0A%0A%09@Test%0A%09public void is_date_a_holiday () %7B%0A%09%09%0A%09%09LocalDate date = LocalDate.of(2014, Month.DECEMBER, 25); // XMAS%0A%0A%09%09Boolean isHoliday = date.query(new CompanyHolidayQuery());%0A%09%09%0A%09%09assertTrue(isHoliday);%0A%09%7D%0A%09%0A%09@Test%0A%09public void is_not_date_a_holiday () %7B%0A%09%09%0A%09%09LocalDate date = LocalDate.of(2014, Month.NOVEMBER, 22);%0A%0A%09%09Boolean isHoliday = date.query(new CompanyHolidayQuery());%0A%09%09%0A%09%09assertFalse(isHoliday);%0A%09%7D%0A%09%0A%7D%0A

add company holiday query java 8 temporal query