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

com.stripe.model.StripeCollection Maven / Gradle / Ivy

There is a newer version: 28.1.0-beta.3
Show newest version
package com.stripe.model;

import com.stripe.net.RequestOptions;
import com.stripe.net.StripeResponseGetter;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

/**
 * Provides a representation of a single page worth of data from the Stripe API.
 *
 * 

The following code will have the effect of iterating through a single page worth of invoice * data retrieve from the API: * *

* *

{@code
 * foreach (Invoice invoice : Invoice.list(...).getData()) {
 *   System.out.println("Current invoice = " + invoice.toString());
 * }
 * }
* *

The class also provides a helper for iterating over collections that may be longer than a * single page: * *

* *

{@code
 * foreach (Invoice invoice : Invoice.list(...).autoPagingIterable()) {
 *   System.out.println("Current invoice = " + invoice.toString());
 * }
 * }
*/ @Getter @Setter @EqualsAndHashCode(callSuper = false) public class StripeCollection extends StripeObject implements StripeCollectionInterface, StripeActiveObject { private transient StripeResponseGetter responseGetter; String object; @Getter(onMethod_ = {@Override}) List data; @Getter(onMethod_ = {@Override}) Boolean hasMore; @Getter(onMethod_ = {@Override}) String url; @Getter(onMethod_ = {@Override}) @Setter(onMethod = @__({@Override})) private transient RequestOptions requestOptions; @Getter(onMethod_ = {@Override}) @Setter(onMethod = @__({@Override})) private Map requestParams; @Setter(onMethod = @__({@Override})) private transient Type pageTypeToken; public Iterable autoPagingIterable() { this.responseGetter.validateRequestOptions(this.requestOptions); return new PagingIterable<>(this, responseGetter, pageTypeToken); } public Iterable autoPagingIterable(Map params) { this.responseGetter.validateRequestOptions(this.requestOptions); this.setRequestParams(params); return new PagingIterable<>(this, responseGetter, pageTypeToken); } /** * Constructs an iterable that can be used to iterate across all objects across all pages. As page * boundaries are encountered, the next page will be fetched automatically for continued * iteration. * * @param params request parameters (will override the parameters from the initial list request) * @param options request options (will override the options from the initial list request) */ public Iterable autoPagingIterable(Map params, RequestOptions options) { this.responseGetter.validateRequestOptions(options); this.setRequestOptions(options); this.setRequestParams(params); return new PagingIterable<>(this, responseGetter, pageTypeToken); } @Override public void setResponseGetter(StripeResponseGetter responseGetter) { this.responseGetter = responseGetter; if (this.data != null) { for (T item : data) { trySetResponseGetter(item, responseGetter); } } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy