From b7cdafd78a7e97c70ceaa3349197eb012e69cc3f Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Wed, 27 Jun 2012 20:35:25 +0900 Subject: [PATCH] Don't pass everything to a function that needs only the head (A2) Change-Id: Ic367836202ab8071c1a9a02eaf0651b0da947d51 --- .../inputmethod/latin/AutoCorrection.java | 23 +++++++++---------- .../android/inputmethod/latin/Suggest.java | 4 +++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/AutoCorrection.java b/java/src/com/android/inputmethod/latin/AutoCorrection.java index 30b681651..b5934111f 100644 --- a/java/src/com/android/inputmethod/latin/AutoCorrection.java +++ b/java/src/com/android/inputmethod/latin/AutoCorrection.java @@ -34,17 +34,17 @@ public class AutoCorrection { public static CharSequence computeAutoCorrectionWord( final ConcurrentHashMap dictionaries, - final WordComposer wordComposer, final ArrayList suggestions, + final WordComposer wordComposer, SuggestedWordInfo suggestion, final CharSequence consideredWord, final float autoCorrectionThreshold, final CharSequence whitelistedWord) { if (hasAutoCorrectionForWhitelistedWord(whitelistedWord)) { return whitelistedWord; } else if (hasAutoCorrectionForConsideredWord( - dictionaries, wordComposer, suggestions, consideredWord)) { + dictionaries, wordComposer, suggestion, consideredWord)) { return consideredWord; - } else if (hasAutoCorrectionForBinaryDictionary(wordComposer, suggestions, + } else if (hasAutoCorrectionForBinaryDictionary(wordComposer, suggestion, consideredWord, autoCorrectionThreshold)) { - return suggestions.get(0).mWord; + return suggestion.mWord; } return null; } @@ -111,27 +111,26 @@ public class AutoCorrection { private static boolean hasAutoCorrectionForConsideredWord( final ConcurrentHashMap dictionaries, - final WordComposer wordComposer, final ArrayList suggestions, + final WordComposer wordComposer, final SuggestedWordInfo suggestion, final CharSequence consideredWord) { if (TextUtils.isEmpty(consideredWord)) return false; - return wordComposer.size() > 1 && suggestions.size() > 0 + return wordComposer.size() > 1 && null != suggestion && !allowsToBeAutoCorrected(dictionaries, consideredWord, false); } private static boolean hasAutoCorrectionForBinaryDictionary(WordComposer wordComposer, - ArrayList suggestions, + SuggestedWordInfo suggestion, CharSequence consideredWord, float autoCorrectionThreshold) { - if (wordComposer.size() > 1 && suggestions.size() > 0) { - final SuggestedWordInfo autoCorrectionSuggestion = suggestions.get(0); + if (wordComposer.size() > 1 && null != suggestion) { //final int autoCorrectionSuggestionScore = sortedScores[0]; - final int autoCorrectionSuggestionScore = autoCorrectionSuggestion.mScore; + final int autoCorrectionSuggestionScore = suggestion.mScore; // TODO: when the normalized score of the first suggestion is nearly equals to // the normalized score of the second suggestion, behave less aggressive. final float normalizedScore = BinaryDictionary.calcNormalizedScore( - consideredWord.toString(), autoCorrectionSuggestion.mWord.toString(), + consideredWord.toString(), suggestion.mWord.toString(), autoCorrectionSuggestionScore); if (DBG) { - Log.d(TAG, "Normalized " + consideredWord + "," + autoCorrectionSuggestion + "," + Log.d(TAG, "Normalized " + consideredWord + "," + suggestion + "," + autoCorrectionSuggestionScore + ", " + normalizedScore + "(" + autoCorrectionThreshold + ")"); } diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 08a7b869d..baf24c8ae 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -249,6 +249,8 @@ public class Suggest { transformedWordInfo.mSourceDict); } + final SuggestedWordInfo bestSuggestion = suggestionsContainer.isEmpty() + ? null : suggestionsContainer.get(0); final CharSequence whitelistedWord = capitalizeWord(isAllUpperCase, isFirstCharCapitalized, mWhiteListDictionary.getWhitelistedWord(consideredWord)); @@ -256,7 +258,7 @@ public class Suggest { if (isCorrectionEnabled) { final CharSequence autoCorrection = AutoCorrection.computeAutoCorrectionWord(mDictionaries, wordComposer, - suggestionsContainer, consideredWord, mAutoCorrectionThreshold, + bestSuggestion, consideredWord, mAutoCorrectionThreshold, whitelistedWord); hasAutoCorrection = (null != autoCorrection); } else {