Skip to content

Commit

Permalink
Fix new PMD warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Jun 7, 2024
1 parent b4e69b3 commit 7d4ca4b
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/main/java/edu/hm/hafner/coverage/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -672,26 +672,25 @@ private String createTargetClassName(final ClassNode testClassNode) {
*
* @return a new tree with the merged {@link Node nodes}
*/
public static Node merge(final List<? extends Node> nodes) {
public static Node merge(final List<Node> nodes) {
if (nodes.isEmpty()) {
throw new IllegalArgumentException("Cannot merge an empty list of nodes");
}
if (nodes.size() == 1) {
return nodes.get(0); // No merge required
}

Map<ImmutablePair<String, Metric>, ? extends List<? extends Node>> grouped = nodes.stream()
Map<ImmutablePair<String, Metric>, ? extends List<Node>> grouped = nodes.stream()
.collect(Collectors.groupingBy(n -> new ImmutablePair<>(n.getName(), n.getMetric())));

if (grouped.size() == 1) {
return nodes.stream()
.map(t -> (Node) t)
.reduce(Node::merge)
.orElseThrow(() -> new NoSuchElementException("No node found"));
}

var container = new ContainerNode("Container"); // non-compatible nodes will be added to a new container node
for (List<? extends Node> matching : grouped.values()) {
for (List<Node> matching : grouped.values()) {
container.addChild(merge(matching));
}
return container;
Expand Down

0 comments on commit 7d4ca4b

Please sign in to comment.