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

Method partitionImpl

corpus/java/training/guava/collect/Iterators.java:576–605  ·  view source on GitHub ↗
(
      final Iterator<T> iterator, final int size, final boolean pad)

Source from the content-addressed store, hash-verified

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

Callers 2

partitionMethod · 0.95
paddedPartitionMethod · 0.95

Calls 2

checkNotNullMethod · 0.45
checkArgumentMethod · 0.45

Tested by

no test coverage detected