Inline a method (A14)
The new code is worse than the old one, but this is a necessary step to make things prettier. Change-Id: If6e8a139bb85e6920c749743c78792a22a8acb45
This commit is contained in:
parent
1333579b4b
commit
074c90af98
2 changed files with 14 additions and 23 deletions
|
@ -31,22 +31,6 @@ public class AutoCorrection {
|
||||||
// Purely static class: can't instantiate.
|
// Purely static class: can't instantiate.
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CharSequence computeAutoCorrectionWord(
|
|
||||||
final ConcurrentHashMap<String, Dictionary> dictionaries,
|
|
||||||
final WordComposer wordComposer, SuggestedWordInfo suggestion,
|
|
||||||
final CharSequence consideredWord, final float autoCorrectionThreshold,
|
|
||||||
final CharSequence whitelistedWord) {
|
|
||||||
if (hasAutoCorrectionForWhitelistedWord(whitelistedWord)) {
|
|
||||||
return whitelistedWord;
|
|
||||||
} else if (shouldAutoCorrectToSelf(dictionaries, consideredWord)) {
|
|
||||||
return consideredWord;
|
|
||||||
} else if (hasAutoCorrectionForBinaryDictionary(suggestion,
|
|
||||||
consideredWord, autoCorrectionThreshold)) {
|
|
||||||
return suggestion.mWord;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isValidWord(final ConcurrentHashMap<String, Dictionary> dictionaries,
|
public static boolean isValidWord(final ConcurrentHashMap<String, Dictionary> dictionaries,
|
||||||
CharSequence word, boolean ignoreCase) {
|
CharSequence word, boolean ignoreCase) {
|
||||||
if (TextUtils.isEmpty(word)) {
|
if (TextUtils.isEmpty(word)) {
|
||||||
|
@ -104,18 +88,18 @@ public class AutoCorrection {
|
||||||
return !isValidWord(dictionaries, word, ignoreCase);
|
return !isValidWord(dictionaries, word, ignoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean hasAutoCorrectionForWhitelistedWord(CharSequence whiteListedWord) {
|
static public boolean hasAutoCorrectionForWhitelistedWord(CharSequence whiteListedWord) {
|
||||||
return whiteListedWord != null;
|
return whiteListedWord != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean shouldAutoCorrectToSelf(
|
public static boolean shouldAutoCorrectToSelf(
|
||||||
final ConcurrentHashMap<String, Dictionary> dictionaries,
|
final ConcurrentHashMap<String, Dictionary> dictionaries,
|
||||||
final CharSequence consideredWord) {
|
final CharSequence consideredWord) {
|
||||||
if (TextUtils.isEmpty(consideredWord)) return false;
|
if (TextUtils.isEmpty(consideredWord)) return false;
|
||||||
return !allowsToBeAutoCorrected(dictionaries, consideredWord, false);
|
return !allowsToBeAutoCorrected(dictionaries, consideredWord, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean hasAutoCorrectionForBinaryDictionary(SuggestedWordInfo suggestion,
|
public static boolean hasAutoCorrectionForBinaryDictionary(SuggestedWordInfo suggestion,
|
||||||
CharSequence consideredWord, float autoCorrectionThreshold) {
|
CharSequence consideredWord, float autoCorrectionThreshold) {
|
||||||
if (null != suggestion) {
|
if (null != suggestion) {
|
||||||
//final int autoCorrectionSuggestionScore = sortedScores[0];
|
//final int autoCorrectionSuggestionScore = sortedScores[0];
|
||||||
|
|
|
@ -230,10 +230,17 @@ public class Suggest {
|
||||||
if (isCorrectionEnabled) {
|
if (isCorrectionEnabled) {
|
||||||
final SuggestedWordInfo bestSuggestion = suggestionsSet.isEmpty()
|
final SuggestedWordInfo bestSuggestion = suggestionsSet.isEmpty()
|
||||||
? null : suggestionsSet.first();
|
? null : suggestionsSet.first();
|
||||||
final CharSequence autoCorrection =
|
final CharSequence autoCorrection;
|
||||||
AutoCorrection.computeAutoCorrectionWord(mDictionaries, wordComposer,
|
if (AutoCorrection.hasAutoCorrectionForWhitelistedWord(whitelistedWord)) {
|
||||||
bestSuggestion, consideredWord, mAutoCorrectionThreshold,
|
autoCorrection = whitelistedWord;
|
||||||
whitelistedWord);
|
} else if (AutoCorrection.shouldAutoCorrectToSelf(mDictionaries, consideredWord)) {
|
||||||
|
autoCorrection = consideredWord;
|
||||||
|
} else if (AutoCorrection.hasAutoCorrectionForBinaryDictionary(bestSuggestion,
|
||||||
|
consideredWord, mAutoCorrectionThreshold)) {
|
||||||
|
autoCorrection = bestSuggestion.mWord;
|
||||||
|
} else {
|
||||||
|
autoCorrection = null;
|
||||||
|
}
|
||||||
hasAutoCorrection = (null != autoCorrection);
|
hasAutoCorrection = (null != autoCorrection);
|
||||||
} else {
|
} else {
|
||||||
hasAutoCorrection = false;
|
hasAutoCorrection = false;
|
||||||
|
|
Loading…
Reference in a new issue