1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package net.smartlab.web.page;
25
26 import java.util.Collection;
27 import java.util.Iterator;
28
29
30
31
32
33
34 public class CollectionPaginator extends Paginator implements Collection {
35
36 private Collection collection;
37
38
39
40
41
42
43 public CollectionPaginator(Collection collection) {
44 this(collection, 0);
45 }
46
47
48
49
50
51
52
53 public CollectionPaginator(Collection collection, int size) {
54 this(collection, size, Paginator.UNLIMITED_PAGES);
55 }
56
57
58
59
60
61
62
63
64 public CollectionPaginator(Collection collection, int size, int pages) {
65 super(size, pages);
66 super.setCount(collection.size());
67 this.collection = collection;
68 }
69
70
71
72
73 protected void setArray() {
74 Object[] temp = collection.toArray();
75 try {
76 java.lang.System.arraycopy(temp, (super.getPage() - 1) * array.length, array, 0, array.length);
77 } catch (IndexOutOfBoundsException ioobe) {
78 java.lang.System.arraycopy(temp, (super.getPage() - 1) * array.length, array, 0, collection.size() % array.length);
79 array[collection.size() % array.length] = null;
80 }
81 }
82
83
84
85
86 public int size() {
87 return collection.size();
88 }
89
90
91
92
93 public void clear() {
94 collection.clear();
95 }
96
97
98
99
100 public boolean isEmpty() {
101 return collection.isEmpty();
102 }
103
104
105
106
107 public Object[] toArray() {
108 return this.array;
109 }
110
111
112
113
114 public boolean add(Object o) {
115 return collection.add(o);
116 }
117
118
119
120
121 public boolean contains(Object o) {
122 return collection.contains(o);
123 }
124
125
126
127
128 public boolean remove(Object o) {
129 return collection.remove(o);
130 }
131
132
133
134
135 public boolean addAll(Collection c) {
136 return collection.addAll(c);
137 }
138
139
140
141
142 public boolean containsAll(Collection c) {
143 return collection.containsAll(c);
144 }
145
146
147
148
149 public boolean removeAll(Collection c) {
150 return collection.removeAll(c);
151 }
152
153
154
155
156 public boolean retainAll(Collection c) {
157 return collection.retainAll(c);
158 }
159
160
161
162
163 public Iterator iterator() {
164 return this;
165 }
166
167
168
169
170 public Object[] toArray(Object[] a) {
171 throw new UnsupportedOperationException();
172 }
173
174 }