public String correct(String aWord){
  if ((aWord.length() < 2) || isNumber(aWord)) {
    return aWord;
  }
  boolean isUpper=isUpperCase(aWord.charAt(0));
  String word=aWord.toLowerCase();
  String correction=cachedCorrections.get(word);
  if (correction == null) {
    correction=getBestCandidate(word);
    cachedCorrections.put(word,correction);
  }
  char[] buffer=correction.toCharArray();
  if (isUpper) {
    buffer[0]=toUpperCase(buffer[0]);
  }
  return new String(buffer);
}

public String correct ( String aWord ) { if ( ( aWord . length ( ) < 2 ) || isNumber ( aWord ) ) { return aWord ; } boolean isUpper = isUpperCase ( aWord . charAt ( 0 ) ) ; String word = aWord . toLowerCase ( ) ; String correction = cachedCorrections . get ( word ) ; if ( correction == null ) { correction = getBestCandidate ( word ) ; cachedCorrections . put ( word , correction ) ; } char [ ] buffer = correction . toCharArray ( ) ; if ( isUpper ) { buffer [ 0 ] = toUpperCase ( buffer [ 0 ] ) ; } return new String ( buffer ) ; }
try to find a correction for the given word . the word may contain up to two edits . if no better alternative is found , the word is returned verbatim . for performance reasons corrections are cached .
