@Test public void testToIndex() throws Exception { PaginationHelper paginationHelper = new PaginationHelper<>(null, null); assertEquals(0, paginationHelper.toIndex(0, 1, 2)); assertEquals(0, paginationHelper.toIndex(1, 0, 2)); assertEquals(0, paginationHelper.toIndex(-1, 1, 2)); assertEquals(0, paginationHelper.toIndex(1, -1, 2)); assertEquals(0, paginationHelper.toIndex(1, 1, -1)); assertEquals(0, paginationHelper.toIndex(20, 10, 5)); assertEquals(0, paginationHelper.toIndex(2, 10, 10)); assertEquals(0, paginationHelper.toIndex(2, 100, 100)); assertEquals(2, paginationHelper.toIndex(1, 10, 2)); assertEquals(11, paginationHelper.toIndex(2, 10, 11)); assertEquals(276, paginationHelper.toIndex(23, 12, 1230)); }
int toIndex(int page, int perPage, int totalEntries) { if (page <= 0 || perPage <= 0 || totalEntries < 0) { return 0; } if ((page - 1) * perPage >= totalEntries) { return 0; } return perPage * page < totalEntries ? perPage * page : totalEntries; }
PaginationHelper { int toIndex(int page, int perPage, int totalEntries) { if (page <= 0 || perPage <= 0 || totalEntries < 0) { return 0; } if ((page - 1) * perPage >= totalEntries) { return 0; } return perPage * page < totalEntries ? perPage * page : totalEntries; } }
PaginationHelper { int toIndex(int page, int perPage, int totalEntries) { if (page <= 0 || perPage <= 0 || totalEntries < 0) { return 0; } if ((page - 1) * perPage >= totalEntries) { return 0; } return perPage * page < totalEntries ? perPage * page : totalEntries; } @Inject  PaginationHelper(PaginationFilter<T> paginationFilter, PaginationComparator<T> paginationComparator); }
PaginationHelper { int toIndex(int page, int perPage, int totalEntries) { if (page <= 0 || perPage <= 0 || totalEntries < 0) { return 0; } if ((page - 1) * perPage >= totalEntries) { return 0; } return perPage * page < totalEntries ? perPage * page : totalEntries; } @Inject  PaginationHelper(PaginationFilter<T> paginationFilter, PaginationComparator<T> paginationComparator); Map<String, Object> paginate(String jsonKey, List<T> list, String filter,
                                        String timezoneOffset, String sort, int page, int perPage); }
PaginationHelper { int toIndex(int page, int perPage, int totalEntries) { if (page <= 0 || perPage <= 0 || totalEntries < 0) { return 0; } if ((page - 1) * perPage >= totalEntries) { return 0; } return perPage * page < totalEntries ? perPage * page : totalEntries; } @Inject  PaginationHelper(PaginationFilter<T> paginationFilter, PaginationComparator<T> paginationComparator); Map<String, Object> paginate(String jsonKey, List<T> list, String filter,
                                        String timezoneOffset, String sort, int page, int perPage);  }