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

jp.gopay.sdk.builders.RetrofitRequestBuilderPaginated Maven / Gradle / Ivy

There is a newer version: 0.11.17
Show newest version
package jp.gopay.sdk.builders;

import jp.gopay.sdk.models.common.BaseId;
import jp.gopay.sdk.models.response.PaginatedList;
import jp.gopay.sdk.models.response.PaginatedListIterable;
import jp.gopay.sdk.models.response.PaginatedListIterator;
import jp.gopay.sdk.models.response.SimpleModel;
import jp.gopay.sdk.types.CursorDirection;
import jp.gopay.sdk.utils.Backoff;
import jp.gopay.sdk.utils.ExponentialBackoff;
import retrofit2.Retrofit;

/**
 * Created by nasu on 2017/06/29.
 */
public abstract class RetrofitRequestBuilderPaginated
        extends RetrofitRequestBuilder, R>
        implements Paginator{

    private Integer limit;
    private CursorDirection cursorDirection;
    private C cursor;

    public RetrofitRequestBuilderPaginated(Retrofit retrofit) {
        super(retrofit);
    }

    @Override
    public T setLimit(Integer limit) {
        this.limit = limit;
        return (T) this;
    }

    @Override
    public T setCursorDirection(CursorDirection cursorDirection) {
        this.cursorDirection = cursorDirection;
        return (T) this;
    }

    @Override
    public T setCursor(C cursor) {
        this.cursor = cursor;
        return (T) this;
    }

    public Integer getLimit() {
        return limit;
    }

    public CursorDirection getCursorDirection() {
        return cursorDirection;
    }

    public C getCursor() {
        return cursor;
    }

    public PaginatedListIterable asIterable() {
        PaginatedListIterator list = new PaginatedListIterator<>(this, 900_000L, createBackoff());
        return new PaginatedListIterable<>(list);
    }

    public PaginatedListIterable asIterable(long timeout) {
        PaginatedListIterator list = new PaginatedListIterator<>(this, timeout, createBackoff());
        return new PaginatedListIterable<>(list);
    }

    public PaginatedListIterable asIterable(long timeout, Backoff backoff) {
        PaginatedListIterator list = new PaginatedListIterator<>(this, timeout, backoff);
        return new PaginatedListIterable<>(list);
    }

    private Backoff createBackoff() {
        return new ExponentialBackoff(1_000L, 30_000L, 1.1, 0.5);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy