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

com.gocardless.http.ListResponse Maven / Gradle / Ivy

There is a newer version: 6.0.0
Show newest version
package com.gocardless.http;

import java.util.List;

/**
 * Represents a page of items returned from the API.
 *
 * @param  the type of an item returned from the API.
 */
public class ListResponse {
    private final List items;
    private final Meta meta;

    ListResponse(List items, Meta meta) {
        this.items = items;
        this.meta = meta;
    }

    /**
     * Returns the items on this page.
     */
    public List getItems() {
        return items;
    }

    /**
     * Returns a cursor that can be used to get the page after this one. If null, then this is the
     * last page.
     */
    public String getAfter() {
        return meta.getCursors().getAfter();
    }

    /**
     * Returns a cursor that can be used to get the page before this one. If null, then this is the
     * first page.
     */
    public String getBefore() {
        return meta.getCursors().getBefore();
    }

    /**
     * Returns the upper bound placed on the number of items returned.
     */
    public int getLimit() {
        return meta.getLimit();
    }

    static class Meta {
        private final Cursors cursors;
        private final int limit;

        Meta(Cursors cursors, int limit) {
            this.cursors = cursors;
            this.limit = limit;
        }

        private Cursors getCursors() {
            return cursors;
        }

        private int getLimit() {
            return limit;
        }

        static class Cursors {
            private final String before;
            private final String after;

            Cursors(String before, String after) {
                this.before = before;
                this.after = after;
            }

            private String getBefore() {
                return before;
            }

            private String getAfter() {
                return after;
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy