@Test public void testPaginationWithPageSizeZero() { PageResult<PaginableItem> pageResult = PAGINATION_EVALUATOR.takePage(Page.empty(), PaginableItems.items(2)); assertThat(pageResult.getPagination().getTotalItems()).isEqualTo(2); assertThat(pageResult.getItems()).isEmpty(); }
public PageResult<T> takePage(Page page, List<T> items) { if (page.getPageSize() < 0) { throw PaginationException.badPageSize(page.getPageSize()); } if (page.getPageSize() == 0) { return takeEmptyPage(page, items); } List<T> itemsCopy = new ArrayList<>(items); itemsCopy.sort(dataComparator); if (StringExt.isEmpty(page.getCursor())) { return takePageWithoutCursor(page, itemsCopy); } Pair<String, Long> decodedCursor = decode(page.getCursor()); return takePageWithCursor(page, itemsCopy, decodedCursor.getLeft(), decodedCursor.getRight()); }
PaginationEvaluator { public PageResult<T> takePage(Page page, List<T> items) { if (page.getPageSize() < 0) { throw PaginationException.badPageSize(page.getPageSize()); } if (page.getPageSize() == 0) { return takeEmptyPage(page, items); } List<T> itemsCopy = new ArrayList<>(items); itemsCopy.sort(dataComparator); if (StringExt.isEmpty(page.getCursor())) { return takePageWithoutCursor(page, itemsCopy); } Pair<String, Long> decodedCursor = decode(page.getCursor()); return takePageWithCursor(page, itemsCopy, decodedCursor.getLeft(), decodedCursor.getRight()); } }
PaginationEvaluator { public PageResult<T> takePage(Page page, List<T> items) { if (page.getPageSize() < 0) { throw PaginationException.badPageSize(page.getPageSize()); } if (page.getPageSize() == 0) { return takeEmptyPage(page, items); } List<T> itemsCopy = new ArrayList<>(items); itemsCopy.sort(dataComparator); if (StringExt.isEmpty(page.getCursor())) { return takePageWithoutCursor(page, itemsCopy); } Pair<String, Long> decodedCursor = decode(page.getCursor()); return takePageWithCursor(page, itemsCopy, decodedCursor.getLeft(), decodedCursor.getRight()); } PaginationEvaluator(Function<T, String> idExtractor, Function<T, Long> timestampExtractor); }
PaginationEvaluator { public PageResult<T> takePage(Page page, List<T> items) { if (page.getPageSize() < 0) { throw PaginationException.badPageSize(page.getPageSize()); } if (page.getPageSize() == 0) { return takeEmptyPage(page, items); } List<T> itemsCopy = new ArrayList<>(items); itemsCopy.sort(dataComparator); if (StringExt.isEmpty(page.getCursor())) { return takePageWithoutCursor(page, itemsCopy); } Pair<String, Long> decodedCursor = decode(page.getCursor()); return takePageWithCursor(page, itemsCopy, decodedCursor.getLeft(), decodedCursor.getRight()); } PaginationEvaluator(Function<T, String> idExtractor, Function<T, Long> timestampExtractor); PageResult<T> takePage(Page page, List<T> items); static Builder<T> newBuilder(); }
PaginationEvaluator { public PageResult<T> takePage(Page page, List<T> items) { if (page.getPageSize() < 0) { throw PaginationException.badPageSize(page.getPageSize()); } if (page.getPageSize() == 0) { return takeEmptyPage(page, items); } List<T> itemsCopy = new ArrayList<>(items); itemsCopy.sort(dataComparator); if (StringExt.isEmpty(page.getCursor())) { return takePageWithoutCursor(page, itemsCopy); } Pair<String, Long> decodedCursor = decode(page.getCursor()); return takePageWithCursor(page, itemsCopy, decodedCursor.getLeft(), decodedCursor.getRight()); } PaginationEvaluator(Function<T, String> idExtractor, Function<T, Long> timestampExtractor); PageResult<T> takePage(Page page, List<T> items); static Builder<T> newBuilder();  }