Created
January 31, 2014 00:21
-
-
Save AustinLMayes/8723026 to your computer and use it in GitHub Desktop.
Required: T, Found Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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