1
2
3
4
5
6
7
8
9 package com.atlassian.core.util.bean;
10
11 import java.io.Serializable;
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import java.util.Collections;
15 import java.util.List;
16
17
18
19
20
21
22 public class PagerFilter implements Serializable
23 {
24 int max = 20;
25 int start = 0;
26
27
28
29
30 public Collection getCurrentPage(Collection itemsCol)
31 {
32 List items = null;
33
34 if (itemsCol instanceof List)
35 items = (List) itemsCol;
36 else
37 items = new ArrayList(itemsCol);
38
39 if (items == null || items.size() == 0)
40 {
41 start = 0;
42 return Collections.EMPTY_LIST;
43 }
44
45
46
47 if (start > items.size())
48 {
49 start = 0;
50 return items.subList(0, max);
51 }
52 else
53 {
54 return items.subList(start, Math.min(start + max, items.size()));
55 }
56 }
57
58 public int getMax()
59 {
60 return max;
61 }
62
63 public void setMax(int max)
64 {
65 this.max = max;
66 }
67
68 public int getStart()
69 {
70 return start;
71 }
72
73 public void setStart(int start)
74 {
75 this.start = start;
76 }
77
78 public int getEnd()
79 {
80 return start + max;
81 }
82
83 public int getNextStart()
84 {
85 return start + max;
86 }
87
88 public int getPreviousStart()
89 {
90 return Math.max(0, start - max);
91 }
92 }