@Test public void testUsesPageSubsetWhenOverMaxPageResults() { PagerImpl pager = new PagerImpl(Collections.singletonMap(PARAMETER_KEY, PARAMETER_VALUE), PagerImpl.MAXIMUM_PAGE_DISPLAY_COUNT + 1, 5); assertThat(pager.getPages()).hasSize(PagerImpl.PAGINATION_RANGE_SIZE + 2); }
@Nonnull @Override public List<PagerPage> getPages() { List<PagerPage> pages = new ArrayList<>(); for (int currentIndex = 1; currentIndex <= totalPages; currentIndex++) { Map<String, String> pageParameters = new HashMap<>(existingQueryParameters); pageParameters.put("page", Integer.toString(currentIndex)); if (inDisplayRange(totalPages, currentIndex) || currentIndex == 1 || currentIndex == totalPages) { pages.add(new PagerPageImpl(currentIndex, pageParameters, true)); } } return pages; }
PagerImpl implements Pager { @Nonnull @Override public List<PagerPage> getPages() { List<PagerPage> pages = new ArrayList<>(); for (int currentIndex = 1; currentIndex <= totalPages; currentIndex++) { Map<String, String> pageParameters = new HashMap<>(existingQueryParameters); pageParameters.put("page", Integer.toString(currentIndex)); if (inDisplayRange(totalPages, currentIndex) || currentIndex == 1 || currentIndex == totalPages) { pages.add(new PagerPageImpl(currentIndex, pageParameters, true)); } } return pages; } }
PagerImpl implements Pager { @Nonnull @Override public List<PagerPage> getPages() { List<PagerPage> pages = new ArrayList<>(); for (int currentIndex = 1; currentIndex <= totalPages; currentIndex++) { Map<String, String> pageParameters = new HashMap<>(existingQueryParameters); pageParameters.put("page", Integer.toString(currentIndex)); if (inDisplayRange(totalPages, currentIndex) || currentIndex == 1 || currentIndex == totalPages) { pages.add(new PagerPageImpl(currentIndex, pageParameters, true)); } } return pages; } PagerImpl(final Map<String, String> existingQueryParameters, final int totalPages, final int currentPageIndex); }
PagerImpl implements Pager { @Nonnull @Override public List<PagerPage> getPages() { List<PagerPage> pages = new ArrayList<>(); for (int currentIndex = 1; currentIndex <= totalPages; currentIndex++) { Map<String, String> pageParameters = new HashMap<>(existingQueryParameters); pageParameters.put("page", Integer.toString(currentIndex)); if (inDisplayRange(totalPages, currentIndex) || currentIndex == 1 || currentIndex == totalPages) { pages.add(new PagerPageImpl(currentIndex, pageParameters, true)); } } return pages; } PagerImpl(final Map<String, String> existingQueryParameters, final int totalPages, final int currentPageIndex); @Override int getCurrentPage(); @Override int getTotalPages(); @Nonnull @Override List<PagerPage> getPages(); @Nonnull @Override Map<String, String> getPreviousPageParameters(); @Nonnull @Override Map<String, String> getNextPageParameters(); @Override boolean getMorePagesBefore(); @Override boolean getMorePagesAfter(); }
PagerImpl implements Pager { @Nonnull @Override public List<PagerPage> getPages() { List<PagerPage> pages = new ArrayList<>(); for (int currentIndex = 1; currentIndex <= totalPages; currentIndex++) { Map<String, String> pageParameters = new HashMap<>(existingQueryParameters); pageParameters.put("page", Integer.toString(currentIndex)); if (inDisplayRange(totalPages, currentIndex) || currentIndex == 1 || currentIndex == totalPages) { pages.add(new PagerPageImpl(currentIndex, pageParameters, true)); } } return pages; } PagerImpl(final Map<String, String> existingQueryParameters, final int totalPages, final int currentPageIndex); @Override int getCurrentPage(); @Override int getTotalPages(); @Nonnull @Override List<PagerPage> getPages(); @Nonnull @Override Map<String, String> getPreviousPageParameters(); @Nonnull @Override Map<String, String> getNextPageParameters(); @Override boolean getMorePagesBefore(); @Override boolean getMorePagesAfter(); static final int MAXIMUM_PAGE_DISPLAY_COUNT; static final int PAGINATION_RANGE_SIZE; }