TaskProgressUtil { static List<TaskProgress> createList(final Map<TaskId, TaskProgress> taskProgressMap, final FindTaskProgressCriteria criteria, final TaskManagerTreeAction treeAction) { final Map<TaskId, TaskProgress> completeIdMap = new HashMap<>(taskProgressMap); final Map<TaskId, Set<TaskProgress>> childMap = new HashMap<>(); taskProgressMap.forEach((taskId, taskProgress) -> { childMap.computeIfAbsent( taskProgress.getId().getParentId(), k -> new HashSet<>()).add(taskProgress); while (taskProgress.getId().getParentId() != null) { final TaskProgress child = taskProgress; final TaskId parentId = child.getId().getParentId(); taskProgress = completeIdMap.computeIfAbsent(parentId, k -> { final TaskProgress parent = new TaskProgress(); parent.setId(parentId); parent.setSubmitTimeMs(child.getSubmitTimeMs()); parent.setTimeNowMs(child.getTimeNowMs()); parent.setTaskName("<<dead>>"); return parent; }); childMap.computeIfAbsent( taskProgress.getId().getParentId(), k -> new HashSet<>()).add(taskProgress); } }); Map<TaskId, Set<TaskProgress>> filteredMap = childMap; if (criteria.getNameFilter() != null && !criteria.getNameFilter().isEmpty()) { filteredMap = filter(completeIdMap, childMap); } final List<TaskProgress> returnList = new ArrayList<>(); buildTree(filteredMap, null, -1, returnList, criteria, treeAction); return returnList; } private  TaskProgressUtil();   }
@Test void testSortByAge() { final FindTaskProgressCriteria criteria = new FindTaskProgressCriteria(); final TaskManagerTreeAction treeAction = new TaskManagerTreeAction(); final Map<TaskId, TaskProgress> totalMap = createMap(criteria); List<TaskProgress> sortedList; criteria.setSort(FindTaskProgressCriteria.FIELD_AGE, false, false); sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction); testList(sortedList, (v1, v2) -> v1.getAgeMs() <= v2.getAgeMs()); criteria.setSort(FindTaskProgressCriteria.FIELD_AGE, true, false); sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction); testList(sortedList, (v1, v2) -> v1.getAgeMs() >= v2.getAgeMs()); criteria.setSort(FindTaskProgressCriteria.FIELD_SUBMIT_TIME, false, false); sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction); testList(sortedList, (v1, v2) -> v1.getSubmitTimeMs() <= v2.getSubmitTimeMs()); criteria.setSort(FindTaskProgressCriteria.FIELD_SUBMIT_TIME, true, false); sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction); testList(sortedList, (v1, v2) -> v1.getSubmitTimeMs() >= v2.getSubmitTimeMs()); criteria.setSort(FindTaskProgressCriteria.FIELD_NAME, false, false); sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction); testList(sortedList, (v1, v2) -> v1.getTaskName().compareTo(v2.getTaskName()) <= 0); criteria.setSort(FindTaskProgressCriteria.FIELD_NAME, true, false); sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction); testList(sortedList, (v1, v2) -> v1.getTaskName().compareTo(v2.getTaskName()) >= 0); criteria.setSort(FindTaskProgressCriteria.FIELD_USER, false, false); sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction); testList(sortedList, (v1, v2) -> v1.getUserName().compareTo(v2.getUserName()) <= 0); criteria.setSort(FindTaskProgressCriteria.FIELD_USER, true, false); sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction); testList(sortedList, (v1, v2) -> v1.getUserName().compareTo(v2.getUserName()) >= 0); criteria.setSort(FindTaskProgressCriteria.FIELD_NODE, false, false); sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction); testList(sortedList, (v1, v2) -> v1.getNodeName().compareTo(v2.getNodeName()) <= 0); criteria.setSort(FindTaskProgressCriteria.FIELD_NODE, true, false); sortedList = TaskProgressUtil.createList(totalMap, criteria, treeAction); testList(sortedList, (v1, v2) -> v1.getNodeName().compareTo(v2.getNodeName()) >= 0); }