org.gitlab4j.api.PagerSpliterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gitlab4j-api Show documentation
Show all versions of gitlab4j-api Show documentation
GitLab4J-API (gitlab4j-api) provides a full featured Java client library for working with GitLab repositories and servers via the GitLab REST API.
package org.gitlab4j.api;
import java.util.Collections;
import java.util.Iterator;
import java.util.Spliterator;
import java.util.function.Consumer;
class PagerSpliterator implements Spliterator {
private Pager pager;
private Iterator elements;
PagerSpliterator(Pager pager) {
this.pager = pager;
if (pager.hasNext()) {
elements = this.pager.next().iterator();
} else {
elements = Collections.emptyIterator();
}
}
@Override
public boolean tryAdvance(Consumer super T> action) {
if (action == null) {
throw new NullPointerException("Action is null");
}
if (elements.hasNext()) {
action.accept(elements.next());
return true;
} else if (pager.hasNext()) {
elements = pager.next().iterator();
if(elements.hasNext()) {
action.accept(elements.next());
return true;
}
}
return false;
}
@Override
public Spliterator trySplit() {
return null;
}
@Override
public long estimateSize() {
return pager.getTotalItems();
}
@Override
public int characteristics() {
return SIZED | NONNULL;
}
}