package cgeo.geocaching.utils; import org.apache.commons.collections4.iterators.IteratorIterable; import org.apache.commons.lang3.NotImplementedException; import java.util.Iterator; import java.util.List; final public class MiscUtils { private MiscUtils() {} // Do not instantiate public static Iterable> buffer(final List original, final int n) { if (n <= 0) { throw new IllegalArgumentException("buffer size must be positive"); } return new IteratorIterable>(new Iterator>() { final int size = original.size(); int next = 0; @Override public boolean hasNext() { return next < size; } @Override public List next() { final List result = original.subList(next, Math.min(next + n, size)); next += n; return result; } @Override public void remove() { throw new NotImplementedException("remove"); } }); } }