Class Spelling

java.lang.Object
com.crossbotics.ftchelper.util.Spelling

public final class Spelling extends Object
"Did you mean ...?" for names typed by hand: a position name, a Tunables field. Used by the library's messages ("no position called "closd" (did you mean closed?)"); handy in your own too.

 String like = Spelling.closest("closd", Arrays.asList("open", "closed"));   // "closed"
 
Docs: docs/modules/util.md
  • Method Details

    • closest

      public static String closest(String name, Collection<String> known)
      The known name that name is most likely a typo of, or null if none is close. Capitals and "_" never matter; then a name of 5 or more letters may be 2 letters off (added, missing or changed), a shorter one (3 or 4 letters) 1 letter.
      Parameters:
      name - what was typed, e.g. "closd"
      known - the real names
      Returns:
      the closest real name, or null
    • distance

      public static int distance(String a, String b)
      How many letters must be added, removed or changed to turn a into b (the "edit distance"). "closd" to "closed" is 1.