Class PaginatedList<T>

java.lang.Object
com.eqixiac.equinix.core.http.response.PaginatedList<T>
Type Parameters:
T - the type of resource in the list
All Implemented Interfaces:
Iterable<T>

public class PaginatedList<T> extends Object implements Iterable<T>
A paginated list of resources returned by Equinix API list operations.

This is an Iterable view of the loaded results plus pagination metadata and automatic page loading - it is deliberately not a List. A server response is not a mutable collection: modeling it as one (the old extends ArrayList) exposed add/ remove/clear/ensureCapacity/... that make no sense for a page of API data. Instead it follows the idiom used by the major cloud SDKs (AWS SDK v2, Google Cloud, Stripe): iterate it directly, call stream(), or take a snapshot with toList().

Usage

PaginatedList<BillingAccount> accounts = portal.billingAccounts().summaries();

// Iterate or stream the current page
for (BillingAccount a : accounts) { ... }
accounts.stream().filter(...).forEach(...);
BillingAccount first = accounts.get(0);

// Pagination metadata
Pagination pagination = accounts.getPagination();

// Load additional pages
while (accounts.hasNextPage()) { accounts.next(); }

// Or load all pages at once, then take a List snapshot
List<BillingAccount> all = accounts.loadAll().toList();
Author:
ianjones
See Also:
  • Constructor Details

  • Method Details

    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • stream

      public Stream<T> stream()
      Streams the currently-loaded items.
      Returns:
      a sequential Stream over the loaded items
    • size

      public int size()
      The number of items currently loaded (on this and any already-loaded pages).
      Returns:
      the loaded item count
    • isEmpty

      public boolean isEmpty()
      Returns:
      true if no items are loaded
    • get

      public T get(int index)
      Returns the loaded item at the given index.
      Parameters:
      index - the zero-based index
      Returns:
      the item at index
    • toList

      public List<T> toList()
      Returns an unmodifiable snapshot of the currently-loaded items as a List.
      Returns:
      an unmodifiable copy of the loaded items
    • hasNextPage

      public boolean hasNextPage()
      Returns true if there are more pages of results available from the API.
      Returns:
      true if a next page exists; false if this is the last page
    • next

      public void next()
      Loads the next page of results from the API and appends them to this list. Does nothing if there are no more pages. After calling this method, the pagination metadata is updated to reflect the newly loaded page.
    • loadAll

      public PaginatedList<T> loadAll()
      Eagerly loads all remaining pages from the API, appending all results to this list. After calling this method, the list contains all available resources and hasNextPage() will return false.
      Returns:
      this list, now containing all resources across all pages
    • toString

      public String toString()
      Overrides:
      toString in class Object