Example usage for com.google.common.collect Iterators paddedPartition

List of usage examples for com.google.common.collect Iterators paddedPartition

Introduction

In this page you can find the example usage for com.google.common.collect Iterators paddedPartition.

Prototype

public static <T> UnmodifiableIterator<List<T>> paddedPartition(Iterator<T> iterator, int size) 

Source Link

Document

Divides an iterator into unmodifiable sublists of the given size, padding the final iterator with null values if necessary.

Usage

From source file:org.calrissian.mango.collect.CloseableIterators.java

/**
 * Divides a closeableiterator into unmodifiable sublists of the given size, padding
 * the final iterator with null values if necessary. For example, partitioning
 * a closeable iterator containing {@code [a, b, c, d, e]} with a partition size of 3
 * yields {@code [[a, b, c], [d, e, null]]} -- an outer iterator containing
 * two inner lists of three elements each, all in the original order.
 *
 * <p>The returned lists implement {@link java.util.RandomAccess}.
 *//* w  ww.  j a  v  a2  s. co m*/
public static <T> CloseableIterator<List<T>> paddedParition(final CloseableIterator<T> iterator,
        final int size) {
    return wrap(Iterators.paddedPartition(iterator, size), iterator);
}