All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jp.gopay.sdk.models.response.PaginatedListIterable Maven / Gradle / Ivy

There is a newer version: 0.11.17
Show newest version
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;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy