(
final Iterator<T> iterator, final int size, final boolean pad)
| 574 | } |
| 575 | |
| 576 | private static <T> UnmodifiableIterator<List<T>> partitionImpl( |
| 577 | final Iterator<T> iterator, final int size, final boolean pad) { |
| 578 | checkNotNull(iterator); |
| 579 | checkArgument(size > 0); |
| 580 | return new UnmodifiableIterator<List<T>>() { |
| 581 | @Override |
| 582 | public boolean hasNext() { |
| 583 | return iterator.hasNext(); |
| 584 | } |
| 585 | |
| 586 | @Override |
| 587 | public List<T> next() { |
| 588 | if (!hasNext()) { |
| 589 | throw new NoSuchElementException(); |
| 590 | } |
| 591 | Object[] array = new Object[size]; |
| 592 | int count = 0; |
| 593 | for (; count < size && iterator.hasNext(); count++) { |
| 594 | array[count] = iterator.next(); |
| 595 | } |
| 596 | for (int i = count; i < size; i++) { |
| 597 | array[i] = null; // for GWT |
| 598 | } |
| 599 | |
| 600 | @SuppressWarnings("unchecked") // we only put Ts in it |
| 601 | List<T> list = Collections.unmodifiableList((List<T>) Arrays.asList(array)); |
| 602 | return (pad || count == size) ? list : list.subList(0, count); |
| 603 | } |
| 604 | }; |
| 605 | } |
| 606 | |
| 607 | /** |
| 608 | * Returns a view of {@code unfiltered} containing all elements that satisfy |
no test coverage detected