collapseSingletonLabels function
Keeps the last value for singletonAutomaticLabelNames, leaves others.
Used so ALLURE_LABEL_* / config overrides replace automatic adapter
labels (e.g. host, framework) instead of leaving two conflicting
values. Other label names may still repeat with different values.
Implementation
List<AllureLabel> collapseSingletonLabels(Iterable<AllureLabel> labels) {
final list = labels.toList(growable: false);
final lastIndexByName = <String, int>{};
for (var index = 0; index < list.length; index++) {
final name = list[index].name;
if (singletonAutomaticLabelNames.contains(name)) {
lastIndexByName[name] = index;
}
}
if (lastIndexByName.isEmpty) {
return list;
}
return <AllureLabel>[
for (var index = 0; index < list.length; index++)
if (!lastIndexByName.containsKey(list[index].name) ||
lastIndexByName[list[index].name] == index)
list[index],
];
}