BatchingVisitables { public static <T> BatchingVisitableView<T> flatten(final int outerBatchHint, final BatchingVisitable<? extends BatchingVisitable<? extends T>> inputs) { com.palantir.logsafe.Preconditions.checkNotNull(inputs); return BatchingVisitableView.of(new AbstractBatchingVisitable<T>() { @Override protected <K extends Exception> void batchAcceptSizeHint(final int batchSizeHint, final ConsistentVisitor<T, K> v) throws K { inputs.batchAccept(outerBatchHint, (AbortingVisitor<List<? extends BatchingVisitable<? extends T>>, K>) bvs -> { for (BatchingVisitable<? extends T> bv : bvs) { @SuppressWarnings("unchecked") BatchingVisitable<T> cast = (BatchingVisitable<T>) bv; if (!cast.batchAccept(batchSizeHint, v)) { 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; }
@Test public void testFlatten() { List<String> firstChars = Lists.newArrayList(); for (int i = 0; i < 10; i++) { firstChars.add("" + (char) ('a' + i)); } BatchingVisitable<String> outerVisitable = BatchingVisitableFromIterable.create(firstChars); BatchingVisitableView<BatchingVisitable<String>> bv = BatchingVisitables.transform(outerVisitable, (prefix) -> { List<String> innerChars = Lists.newArrayList(); for (int i = 0; i < 10; i++) { innerChars.add(prefix + (char) ('0' + i)); } return BatchingVisitableFromIterable.create(innerChars); }); UnmodifiableIterator<String> iter = BatchingVisitables.flatten(7, bv).immutableCopy().iterator(); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { assertEquals("unexpected flattened result", "" + (char) ('a' + i) + (char) ('0' + j), iter.next()); } } }