JSPUtil { public static <T extends Object> List<T> getPageNavigationList(List<T> originList, int page, int pageSize) { if (originList == null) { return new ArrayList<T>(); } int start = (page - 1) * pageSize; int end = start + pageSize; if (end > originList.size()) { end = originList.size(); } if (!originList.isEmpty()) { return originList.subList(start, end); } return originList; }  static void sortTaskArray(Task[] tasks, String sortField, String sortOrder); static void sortTasks(List<Task> tasks, String sortField, String sortOrder); static void sortTaskHistory(List<TaskHistory> tasks, String sortField, String sortOrder); static void sortTaskRunner(List<TaskRunner> taskRunners); static void sortTaskRunnerHistory(List<TaskRunnerHistory> histories); static String getElapsedTime(long startTime, long finishTime); static String getTajoMasterHttpAddr(Configuration config); static List<QueryMasterTask> sortQueryMasterTask(Collection<QueryMasterTask> queryMasterTasks,
                                                          final boolean desc); static List<QueryInProgress> sortQueryInProgress(Collection<QueryInProgress> queryInProgresses,
                                                          final boolean desc); static List<Stage> sortStages(Collection<Stage> stages); static List<StageHistory> sortStageHistories(Collection<StageHistory> stages); static String getMasterActiveLabel(MasterContext context); static String percentFormat(float value); static String tableStatToString(TableStats tableStats); static String tableStatToString(CatalogProtos.TableStatsProto tableStats); static String getPageNavigation(int currentPage, int totalPage, String url); static List<T> getPageNavigationList(List<T> originList, int page, int pageSize);  }
@Test public void testGetPageNavigationList() { List<String> originList = new ArrayList<String>(); for (int i = 0; i < 35; i++) { originList.add("Data" + (i + 1)); } List<String> pageList = JSPUtil.getPageNavigationList(originList, 1, 10); assertEquals(10, pageList.size()); assertEquals("Data1", pageList.get(0)); assertEquals("Data10", pageList.get(9)); pageList = JSPUtil.getPageNavigationList(originList, 2, 10); assertEquals(10, pageList.size()); assertEquals("Data11", pageList.get(0)); assertEquals("Data20", pageList.get(9)); pageList = JSPUtil.getPageNavigationList(originList, 3, 10); assertEquals(10, pageList.size()); assertEquals("Data21", pageList.get(0)); assertEquals("Data30", pageList.get(9)); pageList = JSPUtil.getPageNavigationList(originList, 4, 10); assertEquals(5, pageList.size()); assertEquals("Data31", pageList.get(0)); assertEquals("Data35", pageList.get(4)); }