blob: 9634899b5ec6b075c2430ba65acaeeadf4eec9e0 (
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
32
33
34
35
36
37
38
|
// Copyright Vespa.ai. 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.Distribution;
import com.yahoo.vdslib.distribution.GroupVisitor;
class HierarchicalGroupVisiting {
private final Distribution distribution;
public HierarchicalGroupVisiting(Distribution distribution) {
this.distribution = distribution;
}
/**
* Returns true if the group contains more than one (leaf) group.
*/
public boolean isHierarchical() {
return !distribution.getRootGroup().isLeafGroup();
}
/**
* Invoke the visitor for each leaf group of an implied group. If the group is non-hierarchical
* (flat), the visitor will not be invoked.
*/
public void visit(GroupVisitor visitor) {
if (isHierarchical()) {
distribution.visitGroups(group -> {
if (group.isLeafGroup()) {
return visitor.visitGroup(group);
}
return true;
});
}
}
}
|