MCPcopy Create free account
hub / github.com/antlr/codebuff / partitionImpl

Method partitionImpl

output/java_guava/1.4.17/Iterators.java:608–635  ·  view source on GitHub ↗
(final Iterator<T> iterator, final int size, final boolean pad)

Source from the content-addressed store, hash-verified

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

Callers 2

partitionMethod · 0.95
paddedPartitionMethod · 0.95

Calls 2

checkNotNullMethod · 0.45
checkArgumentMethod · 0.45

Tested by

no test coverage detected