LocalDateRange implements Iterable<LocalDate>, ImmutableBean, Serializable { public static LocalDateRange of(LocalDate startDateInclusive, LocalDate endDate, boolean endDateInclusive) { ArgumentChecker.notNull(startDateInclusive, "startDate"); ArgumentChecker.notNull(endDate, "endDate"); if (endDateInclusive == false && endDate.isBefore(LocalDate.MAX)) { endDate = endDate.minusDays(1); } if (endDate.isBefore(startDateInclusive)) { throw new IllegalArgumentException("Start date must be on or after end date"); } return new LocalDateRange(startDateInclusive, endDate); } @ImmutableConstructor private  LocalDateRange(LocalDate startDate, LocalDate endDate); static LocalDateRange of(LocalDate startDateInclusive, LocalDate endDate, boolean endDateInclusive); static LocalDateRange ofNullUnbounded(LocalDate startDateInclusive, LocalDate endDate, boolean endDateInclusive); LocalDate getStartDateInclusive(); LocalDate getEndDateInclusive(); LocalDate getEndDateExclusive(); boolean isStartDateMinimum(); boolean isEndDateMaximum(); LocalDateRange withStartDate(TemporalAdjuster adjuster); LocalDateRange withEndDate(TemporalAdjuster adjuster); LocalDateRange resolveUnboundedStartDate(LocalDate startDateInclusive); LocalDateRange resolveUnboundedEndDate(LocalDate endDate, boolean endDateInclusive); @Override Iterator<LocalDate> iterator(); @Override String toString(); static LocalDateRange.Meta meta(); @Override LocalDateRange.Meta metaBean(); @Override Property<R> property(String propertyName); @Override Set<String> propertyNames(); @Override boolean equals(Object obj); @Override int hashCode(); static final LocalDateRange ALL; }
@Test(expectedExceptions = IllegalArgumentException.class) public void test_of_2_null1() { LocalDateRange.of(null, LocalDate.of(2012, 7, 30), false); }
@Test(expectedExceptions = IllegalArgumentException.class) public void test_of_2_null2() { LocalDateRange.of(LocalDate.of(2012, 7, 28), null, false); }
@Test(expectedExceptions = IllegalArgumentException.class) public void test_of_2_order() { LocalDateRange.of(LocalDate.of(2012, 7, 30), LocalDate.of(2012, 7, 20), false); }
@Test public void test_iteratorEndInclusive() { LocalDate start = LocalDate.of(2011, 3, 8); LocalDate end = LocalDate.of(2011, 3, 10); LocalDateRange dateRange = LocalDateRange.of(start, end, true); List<LocalDate> expected = ImmutableList.of(start, LocalDate.of(2011, 3, 9), end); assertEquals(expected, Lists.newArrayList(dateRange)); }
@Test public void test_iteratorEndExclusive() { LocalDate start = LocalDate.of(2011, 3, 8); LocalDate end = LocalDate.of(2011, 3, 11); LocalDateRange dateRange = LocalDateRange.of(start, end, false); List<LocalDate> expected = ImmutableList.of(start, LocalDate.of(2011, 3, 9), LocalDate.of(2011, 3, 10)); assertEquals(expected, Lists.newArrayList(dateRange)); }