Class PagedIterable<T>

java.lang.Object
org.kohsuke.github.PagedIterable<T>
Type Parameters:
T - the type of items on each page
All Implemented Interfaces:
Iterable<T>
Direct Known Subclasses:
PagedSearchIterable

public abstract class PagedIterable<T> extends Object implements Iterable<T>
Iterable that returns PagedIterator. PagedIterable is thread-safe but PagedIterator is not. Any one instance of PagedIterator should only be called from a single thread.
Author:
Kohsuke Kawaguchi
  • Constructor Details

    • PagedIterable

      public PagedIterable()
      Instantiate a PagedIterable.
  • Method Details

    • withPageSize

      public PagedIterable<T> withPageSize(int size)
      Sets the pagination size.

      When set to non-zero, each API call will retrieve this many entries.

      Parameters:
      size - the size
      Returns:
      the paged iterable
    • iterator

      @Nonnull public final PagedIterator<T> iterator()
      Returns an iterator over elements of type T.
      Specified by:
      iterator in interface Iterable<T>
      Returns:
      an Iterator.
    • _iterator

      @Nonnull public abstract PagedIterator<T> _iterator(int pageSize)
      Iterator over page items.
      Parameters:
      pageSize - the page size
      Returns:
      the paged iterator
    • toArray

      protected T[] toArray(PagedIterator<T> iterator) throws IOException
      Eagerly walk PagedIterator and return the result in an array.
      Parameters:
      iterator - the PagedIterator to read
      Returns:
      an array of all elements from the PagedIterator
      Throws:
      IOException - if an I/O exception occurs.
    • toArray

      @Nonnull public T[] toArray() throws IOException
      Eagerly walk Iterable and return the result in an array.
      Returns:
      the list
      Throws:
      IOException - if an I/O exception occurs.
    • toList

      @Nonnull public List<T> toList() throws IOException
      Eagerly walk Iterable and return the result in a list.
      Returns:
      the list
      Throws:
      IOException - if an I/O Exception occurs
    • toSet

      @Nonnull public Set<T> toSet() throws IOException
      Eagerly walk Iterable and return the result in a set.
      Returns:
      the set
      Throws:
      IOException - if an I/O Exception occurs