@Test public void testVisitWhile() { List<Long> longList = Lists.newArrayList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L); BatchingVisitable<Long> visitable = ListVisitor.create(longList); BatchingVisitableView<Long> view = BatchingVisitables.visitWhile( BatchingVisitableView.of(visitable), (input) -> input.longValue() < 5L); assertEquals("visitWhile visited the wrong number of elements", 5L, view.size()); assertEquals("visitWhile visited the wrong element first", 0L, view.getFirst().longValue()); assertEquals("visitWhile visited the wrong element last", 4L, view.getLast().longValue()); assertTrue("visitWhile visited the wrong elements", view.immutableCopy().containsAll(ImmutableSet.of(0L, 1L, 2L, 3L, 4L))); visitable = ListVisitor.create(Lists.reverse(longList)); view = BatchingVisitables.visitWhile( BatchingVisitableView.of(visitable), (input) -> input.longValue() >= 5L); assertEquals("visitWhile visited the wrong number of elements", 5L, view.size()); assertEquals("visitWhile visited the wrong element first", 9L, view.getFirst().longValue()); assertEquals("visitWhile visited the wrong element last", 5L, view.getLast().longValue()); assertTrue("visitWhile visited the wrong elements", view.immutableCopy().containsAll(ImmutableSet.of(5L, 6L, 7L, 8L, 9L))); }
public static <T> BatchingVisitableView<T> visitWhile(final BatchingVisitable<T> visitable, final Predicate<T> condition) { return BatchingVisitableView.of(new AbstractBatchingVisitable<T>() { @Override protected <K extends Exception> void batchAcceptSizeHint(int batchSizeHint, final ConsistentVisitor<T, K> v) throws K { visitable.batchAccept(batchSizeHint, batch -> { for (T t : batch) { if (!condition.apply(t)) { return false; } boolean keepGoing = v.visitOne(t); if (!keepGoing) { return false; } } return true; }); } }); }
BatchingVisitables { public static <T> BatchingVisitableView<T> visitWhile(final BatchingVisitable<T> visitable, final Predicate<T> condition) { return BatchingVisitableView.of(new AbstractBatchingVisitable<T>() { @Override protected <K extends Exception> void batchAcceptSizeHint(int batchSizeHint, final ConsistentVisitor<T, K> v) throws K { visitable.batchAccept(batchSizeHint, batch -> { for (T t : batch) { if (!condition.apply(t)) { return false; } boolean keepGoing = v.visitOne(t); if (!keepGoing) { return false; } } return true; }); } }); } }
BatchingVisitables { public static <T> BatchingVisitableView<T> visitWhile(final BatchingVisitable<T> visitable, final Predicate<T> condition) { return BatchingVisitableView.of(new AbstractBatchingVisitable<T>() { @Override protected <K extends Exception> void batchAcceptSizeHint(int batchSizeHint, final ConsistentVisitor<T, K> v) throws K { visitable.batchAccept(batchSizeHint, batch -> { for (T t : batch) { if (!condition.apply(t)) { return false; } boolean keepGoing = v.visitOne(t); if (!keepGoing) { return false; } } return true; }); } }); } private  BatchingVisitables(); }
BatchingVisitables { public static <T> BatchingVisitableView<T> visitWhile(final BatchingVisitable<T> visitable, final Predicate<T> condition) { return BatchingVisitableView.of(new AbstractBatchingVisitable<T>() { @Override protected <K extends Exception> void batchAcceptSizeHint(int batchSizeHint, final ConsistentVisitor<T, K> v) throws K { visitable.batchAccept(batchSizeHint, batch -> { for (T t : batch) { if (!condition.apply(t)) { return false; } boolean keepGoing = v.visitOne(t); if (!keepGoing) { return false; } } return true; }); } }); } private  BatchingVisitables(); static BatchingVisitableView<T> emptyBatchingVisitable(); static BatchingVisitableView<T> singleton(final T t); static long count(BatchingVisitable<?> visitable); static long count(BatchingVisitable<?> visitable, int batchSize); static boolean isEmpty(BatchingVisitable<T> v); static BatchingVisitableView<T> visitWhile(final BatchingVisitable<T> visitable,
            final Predicate<T> condition); @Nullable static T getFirst(BatchingVisitable<T> visitable); @Nullable static T getFirst(BatchingVisitable<T> visitable, @Nullable T defaultElement); static boolean isEqual(BatchingVisitable<T> v, final Iterable<T> it); static boolean isEqual(BatchingVisitable<T> v, final Iterator<T> it); static T getMax(BatchingVisitable<T> v); static T getMax(BatchingVisitable<T> v,
                               final Ordering<? super T> o,
                               @Nullable T defaultElement); static T getMin(BatchingVisitable<T> v); static T getMin(BatchingVisitable<T> v,
                               final Ordering<? super T> o,
                               @Nullable T defaultElement); @Nullable static T getLast(BatchingVisitable<T> visitable); @Nullable static T getLast(BatchingVisitable<T> visitable, @Nullable T defaultElement); static BatchingVisitableView<T> filter(BatchingVisitable<T> visitable, final Predicate<? super T> pred); static BatchingVisitableView<T> transform(BatchingVisitable<F> visitable, final Function<? super F, ? extends T> f); static BatchingVisitableView<T> transformBatch(final BatchingVisitable<F> visitable,
            final Function<? super List<F>, ? extends List<T>> f); static BatchingVisitableView<T> limit(final BatchingVisitable<T> visitable, final long limit); static BatchingVisitableView<T> skip(final BatchingVisitable<T> visitable, final long toSkip); static BatchingVisitableView<T> unique(final BatchingVisitable<T> visitable); static BatchingVisitableView<T> uniqueOn(final BatchingVisitable<T> visitable, final Function<T, ?> function); static List<T> copyToList(BatchingVisitable<T> v); static List<T> take(BatchingVisitable<T> v, int howMany); static List<T> take(BatchingVisitable<T> v, final int howMany, final boolean includeFirst); static TokenBackedBasicResultsPage<T, TOKEN> getFirstPage(BatchingVisitable<T> v,
                                                                                int numToVisitArg,
                                                                                Function<T, TOKEN> tokenExtractor); static TokenBackedBasicResultsPage<T, T> getFirstPage(BatchingVisitable<T> v, int numToVisitArg); static BatchingVisitableView<T> hintPageSize(final BatchingVisitable<T> bv, final int pageSize); static BatchingVisitable<T> wrap(final BatchingVisitable<S> visitable); static BatchingVisitableView<T> concat(BatchingVisitable<? extends T>... inputs); static BatchingVisitableView<T> concat(final Iterable<? extends BatchingVisitable<? extends T>> inputs); static BatchingVisitableView<T> flatten(final int outerBatchHint, final BatchingVisitable<? extends BatchingVisitable<? extends T>> inputs); static BatchingVisitable<Long> getOrderedVisitableUsingSublists(
            final OrderedSublistProvider<Long> sublistProvider, @Inclusive final long startId); static BatchingVisitable<T> getOrderedVisitableUsingSublists(
            final OrderedSublistProvider<T> sublistProvider, @Inclusive final long startId,
            final Function<T, Long> idFunction); }
BatchingVisitables { public static <T> BatchingVisitableView<T> visitWhile(final BatchingVisitable<T> visitable, final Predicate<T> condition) { return BatchingVisitableView.of(new AbstractBatchingVisitable<T>() { @Override protected <K extends Exception> void batchAcceptSizeHint(int batchSizeHint, final ConsistentVisitor<T, K> v) throws K { visitable.batchAccept(batchSizeHint, batch -> { for (T t : batch) { if (!condition.apply(t)) { return false; } boolean keepGoing = v.visitOne(t); if (!keepGoing) { return false; } } return true; }); } }); } private  BatchingVisitables(); static BatchingVisitableView<T> emptyBatchingVisitable(); static BatchingVisitableView<T> singleton(final T t); static long count(BatchingVisitable<?> visitable); static long count(BatchingVisitable<?> visitable, int batchSize); static boolean isEmpty(BatchingVisitable<T> v); static BatchingVisitableView<T> visitWhile(final BatchingVisitable<T> visitable,
            final Predicate<T> condition); @Nullable static T getFirst(BatchingVisitable<T> visitable); @Nullable static T getFirst(BatchingVisitable<T> visitable, @Nullable T defaultElement); static boolean isEqual(BatchingVisitable<T> v, final Iterable<T> it); static boolean isEqual(BatchingVisitable<T> v, final Iterator<T> it); static T getMax(BatchingVisitable<T> v); static T getMax(BatchingVisitable<T> v,
                               final Ordering<? super T> o,
                               @Nullable T defaultElement); static T getMin(BatchingVisitable<T> v); static T getMin(BatchingVisitable<T> v,
                               final Ordering<? super T> o,
                               @Nullable T defaultElement); @Nullable static T getLast(BatchingVisitable<T> visitable); @Nullable static T getLast(BatchingVisitable<T> visitable, @Nullable T defaultElement); static BatchingVisitableView<T> filter(BatchingVisitable<T> visitable, final Predicate<? super T> pred); static BatchingVisitableView<T> transform(BatchingVisitable<F> visitable, final Function<? super F, ? extends T> f); static BatchingVisitableView<T> transformBatch(final BatchingVisitable<F> visitable,
            final Function<? super List<F>, ? extends List<T>> f); static BatchingVisitableView<T> limit(final BatchingVisitable<T> visitable, final long limit); static BatchingVisitableView<T> skip(final BatchingVisitable<T> visitable, final long toSkip); static BatchingVisitableView<T> unique(final BatchingVisitable<T> visitable); static BatchingVisitableView<T> uniqueOn(final BatchingVisitable<T> visitable, final Function<T, ?> function); static List<T> copyToList(BatchingVisitable<T> v); static List<T> take(BatchingVisitable<T> v, int howMany); static List<T> take(BatchingVisitable<T> v, final int howMany, final boolean includeFirst); static TokenBackedBasicResultsPage<T, TOKEN> getFirstPage(BatchingVisitable<T> v,
                                                                                int numToVisitArg,
                                                                                Function<T, TOKEN> tokenExtractor); static TokenBackedBasicResultsPage<T, T> getFirstPage(BatchingVisitable<T> v, int numToVisitArg); static BatchingVisitableView<T> hintPageSize(final BatchingVisitable<T> bv, final int pageSize); static BatchingVisitable<T> wrap(final BatchingVisitable<S> visitable); static BatchingVisitableView<T> concat(BatchingVisitable<? extends T>... inputs); static BatchingVisitableView<T> concat(final Iterable<? extends BatchingVisitable<? extends T>> inputs); static BatchingVisitableView<T> flatten(final int outerBatchHint, final BatchingVisitable<? extends BatchingVisitable<? extends T>> inputs); static BatchingVisitable<Long> getOrderedVisitableUsingSublists(
            final OrderedSublistProvider<Long> sublistProvider, @Inclusive final long startId); static BatchingVisitable<T> getOrderedVisitableUsingSublists(
            final OrderedSublistProvider<T> sublistProvider, @Inclusive final long startId,
            final Function<T, Long> idFunction); static final int DEFAULT_BATCH_SIZE; @SuppressWarnings("unused") // Used in internal legacy code
    static final int KEEP_ALL_BATCH_SIZE; }