RunDashboard: simplify grouping rule's collector

This commit is contained in:
Konstantin Aleev
2017-08-28 12:41:38 +03:00
parent 815835e436
commit 2b14f2f49b
@@ -95,19 +95,16 @@ public class RunDashboardTreeStructure extends AbstractTreeStructureBase {
}
final List<DashboardGroupingRule> remaining = new ArrayList<>(rules);
DashboardGroupingRule rule = remaining.remove(0);
Map<DashboardGroup, List<RunConfigurationNode>> groups = nodes.stream().collect(
HashMap::new,
(map, node) -> map.computeIfAbsent(rule.getGroup(node), key -> new ArrayList<>()).add(node),
(firstMap, secondMap) -> firstMap.forEach((key, value) -> value.addAll(secondMap.get(key)))
);
Map<Optional<DashboardGroup>, List<RunConfigurationNode>> groups = nodes.stream().collect(
Collectors.groupingBy(node -> Optional.ofNullable(rule.getGroup(node))));
final List<AbstractTreeNode> result = new ArrayList<>();
final List<AbstractTreeNode> ungroupedNodes = new ArrayList<>();
groups.forEach((group, groupedNodes) -> {
if (group == null || (!rule.shouldGroupSingleNodes() && groupedNodes.size() == 1)) {
if (!group.isPresent() || (!rule.shouldGroupSingleNodes() && groupedNodes.size() == 1)) {
ungroupedNodes.addAll(group(project, parent, remaining, groupedNodes));
}
else {
GroupingNode node = new GroupingNode(project, parent.getValue(), group);
GroupingNode node = new GroupingNode(project, parent.getValue(), group.get());
node.addChildren(group(project, node, remaining, groupedNodes));
result.add(node);
}