findBestMatch method
Finds best match for given rule in possible subroutes
Implementation
dynamic findBestMatch(
Map selectedRule,
Map<String, dynamic> decisionSubroutes,
) {
final entries = decisionSubroutes.entries.toList();
// ignore: cascade_invocations
entries.sort((first, second) => -first.value.compareTo(second.value));
var latestSelected = selectedRule[entries[0].key];
final maxValue = entries[0].value;
var index = 1;
var maxEquals = 0;
while (index < entries.length && entries[index].value == maxValue) {
final matches = entries[index].key.characters
.where((element) => element == '=')
.length;
if (matches > maxEquals) {
maxEquals = matches;
latestSelected = selectedRule[entries[index].key];
}
index++;
}
return latestSelected;
}