Skip to content

Instantly share code, notes, and snippets.

@Dykam
Forked from AustinLMayes/StringUtils.java
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dykam/8723070 to your computer and use it in GitHub Desktop.
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