com.univapay.sdk.models.response.PaginatedListIterable Maven / Gradle / Ivy
package com.univapay.sdk.models.response;
import com.univapay.sdk.builders.RetrofitRequestBuilderPaginated;
import com.univapay.sdk.types.CursorDirection;
import java.util.List;
public class PaginatedListIterable implements Iterable> {
private final PaginatedListIterator paginatedList;
public PaginatedListIterator getPaginatedList() {
return paginatedList;
}
public PaginatedListIterable(PaginatedListIterator paginatedList) {
this.paginatedList = paginatedList;
}
@Override
public UnivapayPaginatedListIterator iterator() {
if (paginatedList == null) {
throw new NullPointerException();
}
return paginatedList;
}
public PaginatedListIterable reverse() {
RetrofitRequestBuilderPaginated lastBuilder = paginatedList.getLastBuilder();
CursorDirection cursorDirection =
(lastBuilder.getCursorDirection() == CursorDirection.ASC)
? CursorDirection.DESC
: CursorDirection.ASC;
lastBuilder.setCursorDirection(cursorDirection);
if (paginatedList.isNotFirstTime()) {
List items = paginatedList.getItems();
if (!items.isEmpty()) {
paginatedList.setNextCursor(items.get(0).getId());
}
lastBuilder.setCursor(paginatedList.getNextCursor());
paginatedList.setHasMore(true);
}
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy