in build-tools/src/main/java/co/elastic/otel/android/compilation/tools/utils/LicensesIdsMatcher.java [12:36]
public static String findId(String licenseName) {
Map<String, String> ids = getIds();
String matchingId = null;
String comparableName = curateLicenseName(licenseName);
int shortestDistance = (int) Math.ceil(comparableName.length() / 2.0);
LevenshteinDistance distanceFinder = LevenshteinDistance.getDefaultInstance();
for (String id : ids.keySet()) {
String predefinedName = ids.get(id);
int distance = distanceFinder.apply(comparableName, predefinedName);
if (distance > shortestDistance) {
continue;
}
if (distance == shortestDistance && matchingId != null) {
throw new RuntimeException("Ambiguous license id match for: '" + licenseName + "' -> matching ids: (" + matchingId + ", " + id + ")");
}
if (distance == 0) {
return id;
}
shortestDistance = distance;
matchingId = id;
}
return matchingId;
}