1 package com.atlassian.plugins.rest.common.expand.entity;
2
3 import com.atlassian.plugins.rest.common.expand.parameter.Indexes;
4
5 import static javax.xml.bind.annotation.XmlAccessType.FIELD;
6
7 import javax.xml.bind.annotation.XmlAccessorType;
8 import javax.xml.bind.annotation.XmlAttribute;
9 import javax.xml.bind.annotation.XmlRootElement;
10 import java.util.List;
11
12
13
14
15
16
17
18
19
20
21
22 @XmlRootElement
23 @XmlAccessorType(FIELD)
24 public abstract class AbstractPagedListWrapper<T> implements ListWrapper<T> {
25 @XmlAttribute
26 private final int size;
27
28 @XmlAttribute(name = "max-results")
29 private final int maxResults;
30
31 @XmlAttribute(name = "start-index")
32 private Integer startIndex;
33
34
35 private AbstractPagedListWrapper() {
36 size = 0;
37 maxResults = 0;
38 }
39
40 protected AbstractPagedListWrapper(int size, int maxResults) {
41 this.size = size;
42 this.maxResults = maxResults;
43 }
44
45 public Integer getStartIndex() {
46 return startIndex;
47 }
48
49 public int getSize() {
50 return size;
51 }
52
53 public int getMaxResults() {
54 return maxResults;
55 }
56
57 public void setStartIndex(int startIndex) {
58 this.startIndex = startIndex;
59 }
60
61 public final ListWrapperCallback<T> getCallback() {
62 return new ListWrapperCallback<T>() {
63 public List<T> getItems(Indexes indexes) {
64 final int startIndex = indexes.getMinIndex(size);
65 if (startIndex != -1) {
66 setStartIndex(startIndex);
67 }
68 return getPagingCallback().getItems(indexes);
69 }
70 };
71 }
72
73
74
75
76
77
78
79 public abstract ListWrapperCallback<T> getPagingCallback();
80 }