in async/src/main/java/org/apache/geode_examples/async/LevenshteinDistance.java [23:35]
public int calculate(String first, String second) {
if (first == null || first.isEmpty())
return (second == null ? 0 : second.length());
if (second == null || second.isEmpty())
return (first == null ? 0 : first.length());
final String firstPrime = first.substring(0, first.length() - 1);
final String secondPrime = second.substring(0, second.length() - 1);
final int cost =
((first.charAt(first.length() - 1) == second.charAt(second.length() - 1)) ? 0 : 1);
return Math.min(Math.min(calculate(firstPrime, second) + 1, calculate(first, secondPrime) + 1),
calculate(firstPrime, secondPrime) + cost);
}