Skip to content

Instantly share code, notes, and snippets.

@AustinLMayes
Created January 31, 2014 00:21
Show Gist options
  • Save AustinLMayes/8723026 to your computer and use it in GitHub Desktop.
Save AustinLMayes/8723026 to your computer and use it in GitHub Desktop.
Required: T, Found Object
public static final <T> T bestMatch(String search, Collection<T> options, double threshold) {
Object bestObj = null;
double bestScore = 0.0D;
for (Iterator i = options.iterator(); i.hasNext(); ) { Object obj = i.next();
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