@@ -0,0 +1,1993 @@
+package com.levelup.java.date.query;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertTrue;%0A%0Aimport java.time.DayOfWeek;%0Aimport java.time.LocalDate;%0Aimport java.time.Month;%0Aimport java.time.temporal.ChronoField;%0Aimport java.time.temporal.TemporalAccessor;%0Aimport java.time.temporal.TemporalQuery;%0Aimport java.util.List;%0Aimport java.util.stream.Collectors;%0A%0Aimport org.junit.Test;%0A%0Aimport com.google.common.collect.Lists;%0A%0A/**%0A * This java example will demonstrate how to check if %0A * a date is Saturday or Sunday using TemporalQuery.%0A * %0A * @author Justin Musgrove%0A * @see %3Ca href='http://www.leveluplunch.com/java/examples/weekend-temporal-query-java8/'%3EWeekend query%3C/a%3E%0A */%0Apublic class WeekendQuery implements TemporalQuery%3CBoolean%3E %7B%0A%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%09int dayOfWeekNumber = date.get(ChronoField.DAY_OF_WEEK);%0A%09%09DayOfWeek dayOfWeek = DayOfWeek.of(dayOfWeekNumber);%0A%0A%09%09if (dayOfWeek == DayOfWeek.SATURDAY %7C%7C dayOfWeek == DayOfWeek.SUNDAY) %7B%0A%09%09%09return Boolean.TRUE; %0A%09%09%7D else %7B%0A%09%09%09return Boolean.FALSE; %0A%09%09%7D%0A%09%7D%0A%09%0A%09@Test%0A%09public void check_if_date_is_weekend () %7B%0A%09%09%0A%09%09LocalDate date = LocalDate.of(2014, 02, 02); // Sunday%0A%09%09%0A%09%09Boolean workDay = date.query(new WeekendQuery());%0A%0A%09%09assertTrue(workDay);%0A%09%7D%0A%0A%09@Test%0A%09public void filter_dates_by_weekend () %7B%0A%09%09%0A%09%09List%3CLocalDate%3E randomDays = Lists.newArrayList(%0A%09%09%09%09LocalDate.of(2014, Month.FEBRUARY, 16), // Sunday%0A%09%09%09%09LocalDate.of(2014, Month.APRIL, 19), // Saturday%0A%09%09%09%09LocalDate.of(2014, Month.MAY, 30), // Friday%0A%09%09%09%09LocalDate.of(2014, Month.DECEMBER, 12), // Friday%0A%09%09%09%09LocalDate.of(2014, Month.DECEMBER, 17) // Wednesday%0A%09%09%09%09);%0A%0A%09%09// filter weekend days %0A%09%09List%3CLocalDate%3E weekendDays = randomDays%0A%09%09%09%09.stream()%0A%09%09%09%09.filter(p -%3E p.query(new WeekendQuery()))%0A%09%09%09%09.collect(Collectors.toList());%0A%09%09%0A%09%09assertEquals(2, weekendDays.size());%0A%09%7D%0A%0A%09%0A%7D%0A

add weekend query java 8 temporal query