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

Method consumingIterator

output/java_guava/1.4.16/Iterators.java:976–996  ·  view source on GitHub ↗

Returns a view of the supplied iterator that removes each element from the supplied iterator as it is returned. The provided iterator must support Iterator#remove() or else the returned iterator will fail on the first call to next. @param iterator the iterator to

(final Iterator<T> iterator)

Source from the content-addressed store, hash-verified

974
975
976 public static <T> Iterator<T> consumingIterator(final Iterator<T> iterator) {
977 checkNotNull(iterator);
978 return new UnmodifiableIterator<T>() {
979 @Override
980 public boolean hasNext() {
981 return iterator.hasNext();
982 }
983
984 @Override
985 public T next() {
986 T next = iterator.next();
987 iterator.remove();
988 return next;
989 }
990
991 @Override
992 public String toString() {
993 return "Iterators.consumingIterator(...)";
994 }
995 };
996 }
997
998 /**
999 * Deletes and returns the next value from the iterator, or returns

Callers 1

iteratorMethod · 0.95

Calls 1

checkNotNullMethod · 0.45

Tested by

no test coverage detected