class DefaultPagerModel implements PagerModel {

	public Collection<Integer> getPages(int currentPage, int pageCount) {
		Set<Integer> pages = new TreeSet<Integer>();
		
		// we will always display the same number of pages
		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) {
				// currentPage is within startPages
				// add extra pages to the start
				addPages(pages, minStartPages + 1, bufferPages, 1);
			} else if (currentPage >= pageCount - minEndPages) {
				// currentPage is within the endPages
				// add extra pages to the end
				addPages(pages, pageCount - minEndPages, bufferPages, -1);
			} else {
				// add buffer pages around currentPage
				int start = Math.max(minStartPages + 1, currentPage - currentBuffer);
				addPages(pages, start, bufferPages, 1);
			}
		}
		return pages;
	}

}

class DefaultPagerModelTest {

	@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));
	}

}