mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-15 08:21:23 +00:00
80 lines
4.5 KiB
HTML
80 lines
4.5 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>GitHubPageContentsIterable.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">GitHub API for Java</a> > <a href="index.source.html" class="el_package">org.kohsuke.github</a> > <span class="el_source">GitHubPageContentsIterable.java</span></div><h1>GitHubPageContentsIterable.java</h1><pre class="source lang-java linenums">package org.kohsuke.github;
|
|
|
|
import java.io.IOException;
|
|
import java.util.function.Consumer;
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
/**
|
|
* {@link PagedIterable} implementation that take a {@link Consumer} that initializes all the items on each page as they
|
|
* are retrieved.
|
|
*
|
|
* {@link GitHubPageContentsIterable} is immutable and thread-safe, but the iterator returned from {@link #iterator()}
|
|
* is not. Any one instance of iterator should only be called from a single thread.
|
|
*
|
|
* @param <T>
|
|
* the type of items on each page
|
|
*/
|
|
class GitHubPageContentsIterable<T> extends PagedIterable<T> {
|
|
|
|
private final GitHubClient client;
|
|
private final GitHubRequest request;
|
|
private final Class<T[]> receiverType;
|
|
private final Consumer<T> itemInitializer;
|
|
|
|
GitHubPageContentsIterable(GitHubClient client,
|
|
GitHubRequest request,
|
|
Class<T[]> receiverType,
|
|
<span class="fc" id="L28"> Consumer<T> itemInitializer) {</span>
|
|
<span class="fc" id="L29"> this.client = client;</span>
|
|
<span class="fc" id="L30"> this.request = request;</span>
|
|
<span class="fc" id="L31"> this.receiverType = receiverType;</span>
|
|
<span class="fc" id="L32"> this.itemInitializer = itemInitializer;</span>
|
|
<span class="fc" id="L33"> }</span>
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
@Override
|
|
@Nonnull
|
|
public PagedIterator<T> _iterator(int pageSize) {
|
|
<span class="fc" id="L41"> final GitHubPageIterator<T[]> iterator = GitHubPageIterator.create(client, receiverType, request, pageSize);</span>
|
|
<span class="fc" id="L42"> return new GitHubPageContentsIterator(iterator, itemInitializer);</span>
|
|
}
|
|
|
|
/**
|
|
* Eagerly walk {@link Iterable} and return the result in a {@link GitHubResponse} containing an array of {@link T}
|
|
* items.
|
|
*
|
|
* @return the last response with an array containing all the results from all pages.
|
|
* @throws IOException
|
|
* if an I/O exception occurs.
|
|
*/
|
|
@Nonnull
|
|
GitHubResponse<T[]> toResponse() throws IOException {
|
|
<span class="fc" id="L55"> GitHubPageContentsIterator iterator = (GitHubPageContentsIterator) iterator();</span>
|
|
<span class="fc" id="L56"> T[] items = toArray(iterator);</span>
|
|
<span class="fc" id="L57"> GitHubResponse<T[]> lastResponse = iterator.lastResponse();</span>
|
|
<span class="fc" id="L58"> return new GitHubResponse<>(lastResponse, items);</span>
|
|
}
|
|
|
|
/**
|
|
* This class is not thread-safe. Any one instance should only be called from a single thread.
|
|
*/
|
|
private class GitHubPageContentsIterator extends PagedIterator<T> {
|
|
|
|
<span class="fc" id="L66"> public GitHubPageContentsIterator(GitHubPageIterator<T[]> iterator, Consumer<T> itemInitializer) {</span>
|
|
<span class="fc" id="L67"> super(iterator, itemInitializer);</span>
|
|
<span class="fc" id="L68"> }</span>
|
|
|
|
/**
|
|
* Gets the {@link GitHubResponse} for the last page received.
|
|
*
|
|
* @return the {@link GitHubResponse} for the last page received.
|
|
*/
|
|
private GitHubResponse<T[]> lastResponse() {
|
|
<span class="fc" id="L76"> return ((GitHubPageIterator<T[]>) base).finalResponse();</span>
|
|
}
|
|
}
|
|
}
|
|
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html> |