1
/**
2
* 分頁(yè)操作助手類
3
*
4
*/
5
public class PagedList
6
{
7
protected long count; //數(shù)據(jù)的總數(shù)
8
protected int last; //最后一頁(yè)
9
protected int previous;//上一頁(yè)
10
protected int index; //當(dāng)前頁(yè)
11
protected int next; //下一頁(yè)
12
protected boolean hasFirst; //是否首頁(yè)
13
protected boolean hasLast; //是否最后一頁(yè)
14
protected boolean hasNext; //是否有下一頁(yè)
15
protected boolean hasPrevious;//是否有上一頁(yè)
16
protected List pageList; //頁(yè)面顯示的頁(yè)碼集
17
protected List list; //數(shù)據(jù)集
18
19
/**
20
* 構(gòu)造方法,構(gòu)建一個(gè)分頁(yè)類
21
*
22
* @param count 數(shù)據(jù)總數(shù)
23
* @param size 每頁(yè)顯示多少
24
* @param index 當(dāng)前頁(yè)
25
* @param list 數(shù)據(jù)集
26
* @return
27
*/
28
public PagedList(long count, int size, int index, List list)
29
{
30
this.list = list;
31
this.count=count;
32
this.index=index;
33
if(index < 1)
34
index = 1;
35
if(count % (long)size > 0L)
36
last = (int)(count / (long)size + 1L);
37
else
38
last = (int)(count / (long)size);
39
//如果當(dāng)前頁(yè)不是最后一頁(yè),
40
hasNext = hasLast = index < last;
41
//如果有下一頁(yè)
42
if(hasNext)
43
next = index + 1;
44
//如果當(dāng)前頁(yè)不是第一頁(yè),
45
hasPrevious = hasFirst = index > 1;
46
//如果有上一頁(yè)
47
if(hasPrevious)
48
previous = index - 1;
49
//頁(yè)碼集
50
pageList = new ArrayList();
51
int start = 0;
52
int stop = 0;
53
if(index <= 5)
54
{
55
start = 1;
56
if(last > 10)
57
stop = 10;
58
else
59
stop = last;
60
} else
61
{
62
start = index - index % 5;
63
if(last > start + 10)
64
stop = start + 10;
65
else
66
stop = last;
67
}
68
for(int i = start; i <= stop; i++)
69
pageList.add(Integer.valueOf(i));
70
}
71
72
public List getList()
73
{
74
return list;
75
}
76
77
public List getPageList()
78
{
79
return pageList;
80
}
81
82
public long getCount()
83
{
84
return count;
85
}
86
87
public int getPrevious()
88
{
89
return previous;
90
}
91
92
public int getNext()
93
{
94
return next;
95
}
96
97
public int getIndex()
98
{
99
return index;
100
}
101
102
public int getLast()
103
{
104
return last;
105
}
106
107
public boolean hasNext()
108
{
109
return hasNext;
110
}
111
112
public boolean hasPrevious()
113
{
114
return hasPrevious;
115
}
116
117
public boolean hasFirst()
118
{
119
return hasFirst;
120
}
121
122
public boolean hasLast()
123
{
124
return hasLast;
125
}
126
127
128
}
129
130

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

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130
