Last active
August 29, 2015 13:55
-
-
Save Dykam/8723070 to your computer and use it in GitHub Desktop.
This file contains hidden or 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) { | |
| 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