Skip to content

Instantly share code, notes, and snippets.

@Dykam
Last active August 29, 2015 13:55
Show Gist options
  • Select an option

  • Save Dykam/8723070 to your computer and use it in GitHub Desktop.

Select an option

Save Dykam/8723070 to your computer and use it in GitHub Desktop.
public static final <T> T bestMatch(String search, Collection<T> options, double threshold) {
T bestObj = null;
double bestScore = 0.0D;
for (T obj : options) {
double score = LiquidMetal.score(obj.toString(), search);
if (score > bestScore) {
bestObj = obj;
bestScore = score;
} else if (score == bestScore) {
bestObj = null;
}
}
return bestScore < threshold ? null : bestObj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment