@Test public final void shouldGenerateAlternateElementsDueToGivenFunction() { final Function<LocalDate, LocalDate> NEXT_WORKING_DAY = new Function<LocalDate, LocalDate>() { @Override public LocalDate apply(final LocalDate prevDate) { int prevDateDayOfWeek = prevDate.getDayOfWeek(); if (prevDateDayOfWeek == 5) { return prevDate.plusDays(3); } if (prevDateDayOfWeek == 6) { return prevDate.plusDays(2); } return prevDate.plusDays(1); } }; LocalDate thursday = new LocalDate(2014, 8, 14); LazyStream<LocalDate> stream = LazyStream.create(thursday, NEXT_WORKING_DAY); List<LocalDate> nextFourDays = FluentIterable.from(stream).limit(4).toList(); LocalDate friday = thursday.plusDays(1); LocalDate monday = friday.plusDays(3); LocalDate tuesday = monday.plusDays(1); Assert.assertEquals(Lists.newArrayList(thursday, friday, monday, tuesday), nextFourDays); }
public static <U> LazyStream<U> create(final U firstElement, final Function<U, U> inductionStep) { return new LazyStream<U>(firstElement, inductionStep); }
LazyStream implements Iterable<T> { public static <U> LazyStream<U> create(final U firstElement, final Function<U, U> inductionStep) { return new LazyStream<U>(firstElement, inductionStep); } }
LazyStream implements Iterable<T> { public static <U> LazyStream<U> create(final U firstElement, final Function<U, U> inductionStep) { return new LazyStream<U>(firstElement, inductionStep); } private  LazyStream(final T head, final Function<T, T> inductionStep); }
LazyStream implements Iterable<T> { public static <U> LazyStream<U> create(final U firstElement, final Function<U, U> inductionStep) { return new LazyStream<U>(firstElement, inductionStep); } private  LazyStream(final T head, final Function<T, T> inductionStep); static LazyStream<U> create(final U firstElement, final Function<U, U> inductionStep); T head(); LazyStream<T> tail(); LazyStream<T> dropWhile(final Predicate<T> predicate); List<T> takeWhile(final Predicate<T> predicate); @Override Iterator<T> iterator(); @Override boolean equals(final Object obj); @Override int hashCode(); }
LazyStream implements Iterable<T> { public static <U> LazyStream<U> create(final U firstElement, final Function<U, U> inductionStep) { return new LazyStream<U>(firstElement, inductionStep); } private  LazyStream(final T head, final Function<T, T> inductionStep); static LazyStream<U> create(final U firstElement, final Function<U, U> inductionStep); T head(); LazyStream<T> tail(); LazyStream<T> dropWhile(final Predicate<T> predicate); List<T> takeWhile(final Predicate<T> predicate); @Override Iterator<T> iterator(); @Override boolean equals(final Object obj); @Override int hashCode();  }