blob: b94507ff877bf841ed21aadd3846a87b1cdfdaf7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.core;
import com.yahoo.vdslib.distribution.Group;
import java.util.ArrayList;
import java.util.List;
public class LeafGroups {
/**
* Return a list of all groups that do not themselves have any child groups,
* i.e. only the groups that contain nodes.
*
* The output order is not defined.
*/
public static List<Group> enumerateFrom(Group root) {
List<Group> leaves = new ArrayList<>();
visitNode(root, leaves);
return leaves;
}
private static void visitNode(Group node, List<Group> leaves) {
if (node.isLeafGroup()) {
leaves.add(node);
} else {
node.getSubgroups().forEach((idx, g) -> visitNode(g, leaves));
}
}
}
|