-
Notifications
You must be signed in to change notification settings - Fork 368
/
Copy pathStripeCollection.java
99 lines (87 loc) · 2.74 KB
/
StripeCollection.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.stripe.model;
import com.stripe.net.RequestOptions;
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.
*
* <p>The following code will have the effect of iterating through a single page worth of invoice
* data retrieve from the API:
*
* <p>
*
* <pre>{@code
* foreach (Invoice invoice : Invoice.list(...).getData()) {
* System.out.println("Current invoice = " + invoice.toString());
* }
* }</pre>
*
* <p>The class also provides a helper for iterating over collections that may be longer than a
* single page:
*
* <p>
*
* <pre>{@code
* foreach (Invoice invoice : Invoice.list(...).autoPagingIterable()) {
* System.out.println("Current invoice = " + invoice.toString());
* }
* }</pre>
*/
@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
public abstract class StripeCollection<T extends HasId> extends StripeObject
implements StripeCollectionInterface<T> {
String object;
@Getter(onMethod_ = {@Override})
List<T> data;
@Getter(onMethod_ = {@Override})
Boolean hasMore;
@Getter(onMethod_ = {@Override})
String url;
/**
* The {@code count} attribute.
*
* @deprecated Use pagination parameters instead.
* @see <a href="https://stripe.com/docs/api/java#pagination">Pagination</a>
*/
@Deprecated Long count;
/**
* The {@code total_count} attribute.
*
* @deprecated Use pagination parameters instead.
* @see <a href="https://stripe.com/docs/api/java#pagination">Pagination</a>
*/
@Deprecated
@Getter(onMethod_ = {@Override})
Long totalCount;
@Getter(onMethod_ = {@Override})
@Setter(onMethod = @__({@Override}))
private RequestOptions requestOptions;
@Getter(onMethod_ = {@Override})
@Setter(onMethod = @__({@Override}))
private Map<String, Object> requestParams;
public Iterable<T> autoPagingIterable() {
return new PagingIterable<>(this);
}
public Iterable<T> autoPagingIterable(Map<String, Object> params) {
this.setRequestParams(params);
return new PagingIterable<>(this);
}
/**
* 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<T> autoPagingIterable(Map<String, Object> params, RequestOptions options) {
this.setRequestOptions(options);
this.setRequestParams(params);
return new PagingIterable<>(this);
}
}