All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gitlab4j.api.PagerSpliterator Maven / Gradle / Ivy

Go to download

GitLab4J-API (gitlab4j-api) provides a full featured Java client library for working with GitLab repositories and servers via the GitLab REST API.

The newest version!
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 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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy