@Test public void testPaginationWithCursor() { List<PaginableItem> items = PaginableItems.items(100); PaginableItem removed = items.remove(50); Page page = FIRST_PAGE.toBuilder().withCursor(PAGINATION_EVALUATOR.encode(removed)).build(); paginateThroughAllRemainingPages(page, items.subList(50, items.size())); }
@VisibleForTesting String encode(T value) { String id = idExtractor.apply(value); long timeStamp = Evaluators.getOrDefault(timestampExtractor.apply(value), 0L); return Base64.getEncoder().encodeToString((id + '@' + timeStamp).getBytes()); }
PaginationEvaluator { @VisibleForTesting String encode(T value) { String id = idExtractor.apply(value); long timeStamp = Evaluators.getOrDefault(timestampExtractor.apply(value), 0L); return Base64.getEncoder().encodeToString((id + '@' + timeStamp).getBytes()); } }
PaginationEvaluator { @VisibleForTesting String encode(T value) { String id = idExtractor.apply(value); long timeStamp = Evaluators.getOrDefault(timestampExtractor.apply(value), 0L); return Base64.getEncoder().encodeToString((id + '@' + timeStamp).getBytes()); } PaginationEvaluator(Function<T, String> idExtractor, Function<T, Long> timestampExtractor); }
PaginationEvaluator { @VisibleForTesting String encode(T value) { String id = idExtractor.apply(value); long timeStamp = Evaluators.getOrDefault(timestampExtractor.apply(value), 0L); return Base64.getEncoder().encodeToString((id + '@' + timeStamp).getBytes()); } PaginationEvaluator(Function<T, String> idExtractor, Function<T, Long> timestampExtractor); PageResult<T> takePage(Page page, List<T> items); static Builder<T> newBuilder(); }
PaginationEvaluator { @VisibleForTesting String encode(T value) { String id = idExtractor.apply(value); long timeStamp = Evaluators.getOrDefault(timestampExtractor.apply(value), 0L); return Base64.getEncoder().encodeToString((id + '@' + timeStamp).getBytes()); } PaginationEvaluator(Function<T, String> idExtractor, Function<T, Long> timestampExtractor); PageResult<T> takePage(Page page, List<T> items); static Builder<T> newBuilder();  }