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

Method limit

output/java_guava/1.4.19/Iterators.java:934–960  ·  view source on GitHub ↗

Returns a view containing the first limitSize elements of iterator. If iterator contains fewer than limitSize elements, the returned view contains all of its elements. The returned iterator supports remove() if iterator does. @param iterator the itera

(final Iterator<T> iterator, final int limitSize)

Source from the content-addressed store, hash-verified

932
933
934 public static <T> Iterator<T> limit(final Iterator<T> iterator, final int limitSize) {
935 checkNotNull(iterator);
936 checkArgument(limitSize >= 0, "limit is negative");
937 return new Iterator<T>() {
938 private int count;
939
940 @Override
941 public boolean hasNext() {
942 return count < limitSize && iterator.hasNext();
943 }
944
945 @Override
946 public T next() {
947 if (!hasNext()) {
948 throw new NoSuchElementException();
949 }
950
951 count++;
952 return iterator.next();
953 }
954
955 @Override
956 public void remove() {
957 iterator.remove();
958 }
959 };
960 }
961
962 /**
963 * Returns a view of the supplied {@code iterator} that removes each element

Callers 1

iteratorMethod · 0.95

Calls 2

checkNotNullMethod · 0.45
checkArgumentMethod · 0.45

Tested by

no test coverage detected