@@ -30,14 +30,33 @@ public class PagedResponse<T> {
3030 final String previous ;
3131 final int pages ;
3232 final List <T > list ;
33-
34- public PagedResponse (Class <T > clazz , String self , String next , String previous , int pages , List <T > list ) {
33+ final int total ;
34+
35+ // public PagedResponse(Class<T> clazz, String self, String next, String previous, int pages, List<T> list) {
36+ // this.clazz = clazz;
37+ // this.self = self;
38+ // this.next = next;
39+ // this.previous = previous;
40+ // this.pages = pages;
41+ // this.list = list;
42+ // }
43+
44+ public PagedResponse (Class <T > clazz , String self , String next , String previous , int pages , List <T > list , int total ) {
3545 this .clazz = clazz ;
3646 this .self = self ;
3747 this .next = next ;
3848 this .previous = previous ;
3949 this .pages = pages ;
4050 this .list = list ;
51+ this .total = total ;
52+ }
53+
54+ public int getPages () {
55+ return pages ;
56+ }
57+
58+ public int getTotal () {
59+ return total ;
4160 }
4261
4362 public boolean hasNext () {
@@ -88,6 +107,7 @@ public static class Builder<BT> {
88107 private List <BT > posts ;
89108 private int pages ;
90109 private Class <BT > t1 ;
110+ private int total ;
91111
92112 private Builder (Class <BT > t1 ) {
93113 this .t1 = t1 ;
@@ -118,21 +138,29 @@ public Builder<BT> withPosts(List<BT> posts) {
118138 }
119139
120140 public PagedResponse <BT > build () {
121- return new PagedResponse <>(t1 , self , next , previous , pages , posts );
141+ return new PagedResponse <>(t1 , self , next , previous , pages , posts , total );
122142 }
123143
124144 public Builder <BT > withPages (int pages ) {
125145 this .pages = pages ;
126146 return this ;
127147 }
128148
149+ public Builder <BT > withPages (int pages , int total ) {
150+ this .pages = pages ;
151+ this .total = total ;
152+ return this ;
153+ }
154+
129155 public Builder <BT > withPages (HttpHeaders headers ) {
130156 Optional <String > totalPages = headers .keySet ().stream ().filter (x -> Strings .HEADER_TOTAL_PAGES .compareToIgnoreCase (x ) == 0 ).findFirst ();
131- LOG .debug ("found pages {} from headers {}" , totalPages , headers );
157+ Optional <String > totalOptional = headers .keySet ().stream ().filter (x -> Strings .HEADER_TOTAL .compareToIgnoreCase (x ) == 0 ).findFirst ();
158+ LOG .debug ("found pages {}, total {} from headers {}" , totalPages , totalOptional , headers );
132159 Stream <String > totalPageHeader = totalPages .map (x -> headers .get (x )).map (x -> x .stream ()).orElse (Stream .empty ());
133- totalPageHeader .findFirst ().ifPresent (pages -> Builder .this .withPages (Integer .valueOf (pages )));
160+ int page = Integer .valueOf (totalPageHeader .findFirst ().get ());
161+ Stream <String > totalHeader = totalOptional .map (x -> headers .get (x )).map (x -> x .stream ()).orElse (Stream .empty ());
162+ totalHeader .findFirst ().ifPresent (total -> Builder .this .withPages (page , Integer .valueOf (total )));
134163 return this ;
135164 }
136-
137165 }
138166}
0 commit comments