(final Iterator<T> iterator, final int size, final boolean pad)
| 606 | } |
| 607 | |
| 608 | private static <T> UnmodifiableIterator<List<T>> partitionImpl(final Iterator<T> iterator, final int size, final boolean pad) { |
| 609 | checkNotNull(iterator); |
| 610 | checkArgument(size > 0); |
| 611 | return new UnmodifiableIterator<List<T>>() { |
| 612 | @Override |
| 613 | public boolean hasNext() { |
| 614 | return iterator.hasNext(); |
| 615 | } |
| 616 | |
| 617 | @Override |
| 618 | public List<T> next() { |
| 619 | if (!hasNext()) { |
| 620 | throw new NoSuchElementException(); |
| 621 | } |
| 622 | Object[] array = new Object[size]; |
| 623 | int count = 0; |
| 624 | for (; count < size && iterator.hasNext(); count++) { |
| 625 | array[count] = iterator.next(); |
| 626 | } |
| 627 | for (int i = count; i < size; i++) { |
| 628 | array[i] = null; // for GWT |
| 629 | } |
| 630 | @SuppressWarnings("unchecked") // we only put Ts in it |
| 631 | List<T> list = Collections.unmodifiableList((List<T>) Arrays.asList(array)); |
| 632 | return (pad || count == size) ? list : list.subList(0, count); |
| 633 | } |
| 634 | }; |
| 635 | } |
| 636 | |
| 637 | /** |
| 638 | * Returns a view of {@code unfiltered} containing all elements that satisfy |
no test coverage detected