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

Method consumingIterator

output/java_guava/1.4.19/Iterators.java:977–997  ·  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

975
976
977 public static <T> Iterator<T> consumingIterator(final Iterator<T> iterator) {
978 checkNotNull(iterator);
979 return new UnmodifiableIterator<T>() {
980 @Override
981 public boolean hasNext() {
982 return iterator.hasNext();
983 }
984
985 @Override
986 public T next() {
987 T next = iterator.next();
988 iterator.remove();
989 return next;
990 }
991
992 @Override
993 public String toString() {
994 return "Iterators.consumingIterator(...)";
995 }
996 };
997 }
998
999 /**
1000 * 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