Files
github-api/jacoco/org.kohsuke.github/GitHubPageContentsIterable.java.html
2021-06-02 11:09:28 -07:00

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> &gt; <a href="index.source.html" class="el_package">org.kohsuke.github</a> &gt; <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 &lt;T&gt;
* the type of items on each page
*/
class GitHubPageContentsIterable&lt;T&gt; extends PagedIterable&lt;T&gt; {
private final GitHubClient client;
private final GitHubRequest request;
private final Class&lt;T[]&gt; receiverType;
private final Consumer&lt;T&gt; itemInitializer;
GitHubPageContentsIterable(GitHubClient client,
GitHubRequest request,
Class&lt;T[]&gt; receiverType,
<span class="fc" id="L28"> Consumer&lt;T&gt; 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&lt;T&gt; _iterator(int pageSize) {
<span class="fc" id="L41"> final GitHubPageIterator&lt;T[]&gt; 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&lt;T[]&gt; 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&lt;T[]&gt; lastResponse = iterator.lastResponse();</span>
<span class="fc" id="L58"> return new GitHubResponse&lt;&gt;(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&lt;T&gt; {
<span class="fc" id="L66"> public GitHubPageContentsIterator(GitHubPageIterator&lt;T[]&gt; iterator, Consumer&lt;T&gt; 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&lt;T[]&gt; lastResponse() {
<span class="fc" id="L76"> return ((GitHubPageIterator&lt;T[]&gt;) 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>