JSPUtil { public static void sortTaskArray(Task[] tasks, String sortField, String sortOrder) { if(sortField == null || sortField.isEmpty()) { sortField = "id"; } Arrays.sort(tasks, new TaskComparator(sortField, "asc".equals(sortOrder))); }  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 testSortTask() throws Exception { List<Task> tasks = new ArrayList<Task>(); Configuration conf = new TajoConf(); TaskAttemptToSchedulerEvent.TaskAttemptScheduleContext scheduleContext = new TaskAttemptToSchedulerEvent.TaskAttemptScheduleContext(); ExecutionBlockId ebId = TajoIdUtils.createExecutionBlockId("eb_000001_00001_00001"); for (int i = 0; i < 10; i++) { TaskId id = new TaskId(ebId, i); Task task = new Task(conf, scheduleContext, id, true, null); tasks.add(task); int launchTime = i + 1; int runningTime = i + 1; if(i < 9) { task.setLaunchTime(launchTime); task.setFinishTime(launchTime + runningTime); } } Collections.shuffle(tasks); Task[] taskArray = tasks.toArray(new Task[]{}); JSPUtil.sortTaskArray(taskArray, "id", "asc"); for (int i = 0; i < 10; i++) { assertEquals(i, taskArray[i].getId().getId()); } taskArray = tasks.toArray(new Task[]{}); JSPUtil.sortTaskArray(taskArray, "id", "desc"); for (int i = 0; i < 10; i++) { assertEquals(9 - i, taskArray[i].getId().getId()); } taskArray = tasks.toArray(new Task[]{}); JSPUtil.sortTaskArray(taskArray, "runTime", "asc"); assertEquals(0, taskArray[0].getId().getId()); assertEquals(9, taskArray[9].getId().getId()); taskArray = tasks.toArray(new Task[]{}); JSPUtil.sortTaskArray(taskArray, "runTime", "desc"); assertEquals(8, taskArray[0].getId().getId()); assertEquals(9, taskArray[9].getId().getId()); }