jp.gopay.sdk.models.response.PaginatedListIterable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gopay-java-sdk Show documentation
Show all versions of gopay-java-sdk Show documentation
Official Gyro-n Payments Java SDK
package jp.gopay.sdk.models.response;
import jp.gopay.sdk.builders.RetrofitRequestBuilderPaginated;
import jp.gopay.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 GoPayPaginatedListIterator 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;
}
}