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>
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 Summary
ConstructorsConstructorDescriptionPaginatedList(Iterable<? extends T> initialItems, Pageable<T> pageableClient, EquinixRequest<?> equinixRequest, EquinixResponse<?> equinixResponse, Pagination pagination) -
Method Summary
Modifier and TypeMethodDescriptionget(int index) Returns the loaded item at the given index.booleanReturnstrueif there are more pages of results available from the API.booleanisEmpty()iterator()loadAll()Eagerly loads all remaining pages from the API, appending all results to this list.voidnext()Loads the next page of results from the API and appends them to this list.intsize()The number of items currently loaded (on this and any already-loaded pages).stream()Streams the currently-loaded items.toList()Returns an unmodifiable snapshot of the currently-loaded items as aList.toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
PaginatedList
public PaginatedList(Iterable<? extends T> initialItems, Pageable<T> pageableClient, EquinixRequest<?> equinixRequest, EquinixResponse<?> equinixResponse, Pagination pagination) - Parameters:
initialItems- the items for the current page (any iterable; copied in).
-
-
Method Details
-
iterator
-
stream
-
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:
trueif no items are loaded
-
get
Returns the loaded item at the given index.- Parameters:
index- the zero-based index- Returns:
- the item at
index
-
toList
-
hasNextPage
public boolean hasNextPage()Returnstrueif there are more pages of results available from the API.- Returns:
trueif a next page exists;falseif 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
Eagerly loads all remaining pages from the API, appending all results to this list. After calling this method, the list contains all available resources andhasNextPage()will returnfalse.- Returns:
- this list, now containing all resources across all pages
-
toString
-