@Override public Iterator<List<T>> iterator() { return Iterators.partition(iterable.iterator(), size); } };
@Override public Iterator<List<T>> iterator() { return Iterators.partition(iterable.iterator(), size); } };
@Override public Iterator<List<T>> iterator() { return Iterators.partition(iterable.iterator(), size); } };
public void testPartition_view() { List<Integer> list = asList(1, 2); Iterator<List<Integer>> partitions = Iterators.partition(list.iterator(), 1); // Changes before the partition is retrieved are reflected list.set(0, 3); List<Integer> first = partitions.next(); // Changes after are not list.set(0, 4); assertEquals(ImmutableList.of(3), first); }
@Override protected Iterator<List<Integer>> newTargetIterator() { Iterator<Integer> source = Iterators.forArray(1, 2, 3, 4, 5, 6, 7); return Iterators.partition(source, 3); } }.test();
public void testPartition_empty() { Iterator<Integer> source = Iterators.emptyIterator(); Iterator<List<Integer>> partitions = Iterators.partition(source, 1); assertFalse(partitions.hasNext()); }
@GwtIncompatible // ? // TODO: Figure out why this is failing in GWT. public void testPartitionRandomAccess() { Iterator<Integer> source = asList(1, 2, 3).iterator(); Iterator<List<Integer>> partitions = Iterators.partition(source, 2); assertTrue(partitions.next() instanceof RandomAccess); assertTrue(partitions.next() instanceof RandomAccess); }
public void testPartition_badSize() { Iterator<Integer> source = Iterators.singletonIterator(1); try { Iterators.partition(source, 0); fail(); } catch (IllegalArgumentException expected) { } }
public void testPartition_singleton1() { Iterator<Integer> source = Iterators.singletonIterator(1); Iterator<List<Integer>> partitions = Iterators.partition(source, 1); assertTrue(partitions.hasNext()); assertTrue(partitions.hasNext()); assertEquals(ImmutableList.of(1), partitions.next()); assertFalse(partitions.hasNext()); }
public void testPartition_singleton2() { Iterator<Integer> source = Iterators.singletonIterator(1); Iterator<List<Integer>> partitions = Iterators.partition(source, 2); assertTrue(partitions.hasNext()); assertTrue(partitions.hasNext()); assertEquals(ImmutableList.of(1), partitions.next()); assertFalse(partitions.hasNext()); }
/** Detects Integer.MAX_VALUE and prevents OOM exceptions */ private <T> Iterator<Iterator<T>> safePartition(final Iterator<T> input, int chunkSize) { // Cloud Datastore library errors if you try to fetch more than 1000 keys at a time if (chunkSize > 1000) { chunkSize = 1000; } return Iterators.transform(Iterators.partition(input, chunkSize), IterateFunction.instance()); }
PeekingIterator<RowResult<Value>> peekingValues = Iterators.peekingIterator(valueResults.get()); Iterator<List<RowResult<Set<Long>>>> tsBatches = Iterators.partition(tsResults.get(), range.getBatchHint()); Iterator<List<CandidateCellForSweeping>> candidates = Iterators.transform(tsBatches, tsBatch -> { List<CandidateCellForSweeping> candidateBatch = Lists.newArrayList();
@Override public Iterator<List<T>> iterator() { return Iterators.partition(iterable.iterator(), size); } };
@Override public Iterator<List<T>> iterator() { return Iterators.partition(iterable.iterator(), size); } };
@Override public Iterator<List<T>> iterator() { return Iterators.partition(iterable.iterator(), size); } };
public Iterator<List<T>> iterator() { return Iterators.partition(iterable.iterator(), size); } };
/** * Divides a closeableiterator into unmodifiable sublists of the given size (the final * list may be smaller). For example, partitioning a closeableiterator containing * {@code [a, b, c, d, e]} with a partition size of 3 yields {@code * [[a, b, c], [d, e]]} -- an outer iterator containing two inner lists of * three and two elements, all in the original order. * <p/> * <p>The returned lists implement {@link java.util.RandomAccess}. */ public static <T> CloseableIterator<List<T>> partition(final CloseableIterator<T> iterator, final int size) { return wrap(Iterators.partition(iterator, size), iterator); }
@Override protected Iterator<List<Integer>> newTargetIterator() { Iterator<Integer> source = Iterators.forArray(1, 2, 3, 4, 5, 6, 7); return Iterators.partition(source, 3); } }.test();
public void testPartition_view() { List<Integer> list = asList(1, 2); Iterator<List<Integer>> partitions = Iterators.partition(list.iterator(), 1); // Changes before the partition is retrieved are reflected list.set(0, 3); List<Integer> first = partitions.next(); // Changes after are not list.set(0, 4); assertEquals(ImmutableList.of(3), first); }
public void testPartition_badSize() { Iterator<Integer> source = Iterators.singletonIterator(1); try { Iterators.partition(source, 0); fail(); } catch (IllegalArgumentException expected) { } }