-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPaginationHelper.java
More file actions
41 lines (30 loc) · 1.07 KB
/
PaginationHelper.java
File metadata and controls
41 lines (30 loc) · 1.07 KB
1
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
package matrix;
import java.util.List;
public class PaginationHelper {
public static void main(String[] args) {
}
class PaginationHelper1<I> {
private final List<I> collection;
private final int itemsPerPage;
public PaginationHelper1(List<I> collection, int itemsPerPage) {
this.collection = collection;
this.itemsPerPage = itemsPerPage;
}
public int itemCount() {
return collection.size();
}
public int pageCount() {
double result = (double) collection.size() / itemsPerPage;
return (int) Math.ceil(result);
}
public int pageItemCount(int pageIndex) {
if (pageIndex < 0 || pageIndex >= pageCount()) return -1;
if (pageIndex == pageCount() - 1) return collection.size() % itemsPerPage;
return itemsPerPage;
}
public int pageIndex(int itemIndex) {
if (itemIndex < 0 || itemIndex >= collection.size()) return -1;
return itemIndex / itemsPerPage;
}
}
}