mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-10 08:21:21 +00:00
fixed issue #20
PagedIterator is updated to cope with the base iterator returning array of length 0
This commit is contained in:
@@ -3,6 +3,7 @@ package org.kohsuke.github;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* Iterator over a pagenated data source.
|
||||
@@ -28,17 +29,24 @@ public abstract class PagedIterator<T> implements Iterator<T> {
|
||||
protected abstract void wrapUp(T[] page);
|
||||
|
||||
public boolean hasNext() {
|
||||
return (current!=null && pos<current.length) || base.hasNext();
|
||||
fetch();
|
||||
return current!=null;
|
||||
}
|
||||
|
||||
public T next() {
|
||||
fetch();
|
||||
|
||||
if (current==null) throw new NoSuchElementException();
|
||||
return current[pos++];
|
||||
}
|
||||
|
||||
private void fetch() {
|
||||
while (current==null || current.length<=pos) {
|
||||
if (!base.hasNext()) {// no more to retrieve
|
||||
current = null;
|
||||
pos = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
current = base.next();
|
||||
wrapUp(current);
|
||||
pos = 0;
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.kohsuke.github.GHEventPayload;
|
||||
import org.kohsuke.github.GHHook;
|
||||
import org.kohsuke.github.GHBranch;
|
||||
import org.kohsuke.github.GHIssue;
|
||||
import org.kohsuke.github.GHIssueComment;
|
||||
import org.kohsuke.github.GHIssueState;
|
||||
import org.kohsuke.github.GHKey;
|
||||
import org.kohsuke.github.GHMyself;
|
||||
@@ -51,6 +52,17 @@ public class AppTest extends TestCase {
|
||||
assertFalse(GitHub.connect("totally", "bogus").isCredentialValid());
|
||||
}
|
||||
|
||||
public void testIssueWithNoComment() throws IOException {
|
||||
GHRepository repository = GitHub.connect().getRepository("kohsuke/github-api");
|
||||
List<GHIssueComment> v = repository.getIssue(13).getComments();
|
||||
System.out.println(v);
|
||||
assertTrue(v.isEmpty());
|
||||
|
||||
v = repository.getIssue(5).getComments();
|
||||
System.out.println(v);
|
||||
assertTrue(v.size()==3);
|
||||
}
|
||||
|
||||
public void testRateLimit() throws IOException {
|
||||
System.out.println(GitHub.connect().getRateLimit());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user