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

Method limit

output/java_guava/1.4.16/Iterators.java:933–959  ·  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

931
932
933 public static <T> Iterator<T> limit(final Iterator<T> iterator, final int limitSize) {
934 checkNotNull(iterator);
935 checkArgument(limitSize >= 0, "limit is negative");
936 return new Iterator<T>() {
937 private int count;
938
939 @Override
940 public boolean hasNext() {
941 return count < limitSize && iterator.hasNext();
942 }
943
944 @Override
945 public T next() {
946 if (!hasNext()) {
947 throw new NoSuchElementException();
948 }
949
950 count++;
951 return iterator.next();
952 }
953
954 @Override
955 public void remove() {
956 iterator.remove();
957 }
958 };
959 }
960
961 /**
962 * 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