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