DefaultPagerModel implements PagerModel { public Collection<Integer> getPages(int currentPage, int pageCount) { Set<Integer> pages = new TreeSet<Integer>(); int requiredPages = minStartPages + minEndPages + 1 + (currentBuffer * 2); if (pageCount <= requiredPages) { addPages(pages, 1, pageCount, 1); } else { int bufferPages = 1 + (currentBuffer * 2); addPages(pages, 1, minStartPages, 1); addPages(pages, pageCount, minEndPages, -1); if (currentPage <= minStartPages) { addPages(pages, minStartPages + 1, bufferPages, 1); } else if (currentPage >= pageCount - minEndPages) { addPages(pages, pageCount - minEndPages, bufferPages, -1); } else { int start = Math.max(minStartPages + 1, currentPage - currentBuffer); addPages(pages, start, bufferPages, 1); } } return pages; } DefaultPagerModel(int minEndPages, int currentBuffer, int nextPrevThreshold);  DefaultPagerModel(int minStartPages, int minEndPages, int currentBuffer, int prevThreshold, int nextThreshold); Collection<Integer> getPages(int currentPage, int pageCount); boolean isShowNext(int currentPage, int pageCount); boolean isShowPrevious(int currentPage, int pageCount);  }
@Test public void testGetPages() { DefaultPagerModel pagerModel = new DefaultPagerModel(2, 2, 1, 2, 2); assertPages(new int[] {1,2,3,4,5,9,10}, pagerModel.getPages(1, 10)); assertPages(new int[] {1,2,3,4,5,9,10}, pagerModel.getPages(2, 10)); assertPages(new int[] {1,2,3,4,5,9,10}, pagerModel.getPages(3, 10)); assertPages(new int[] {1,2,3,4,5,9,10}, pagerModel.getPages(4, 10)); assertPages(new int[] {1,2,4,5,6,9,10}, pagerModel.getPages(5, 10)); assertPages(new int[] {1,2,5,6,7,9,10}, pagerModel.getPages(6, 10)); assertPages(new int[] {1,2,6,7,8,9,10}, pagerModel.getPages(7, 10)); assertPages(new int[] {1,2,6,7,8,9,10}, pagerModel.getPages(8, 10)); assertPages(new int[] {1,2,6,7,8,9,10}, pagerModel.getPages(9, 10)); assertPages(new int[] {1,2,6,7,8,9,10}, pagerModel.getPages(10, 10)); }