From 0d0f182959600d83c376e6b844337ea45e5ddbbf Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Wed, 14 Mar 2012 18:43:32 +0900 Subject: [PATCH] Cut out a private method to make things more readable Change-Id: I791700890338e023bd86b8794dbc90379b91dc7d --- .../android/inputmethod/latin/Suggest.java | 56 +++++++++++-------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 19b6c0b31..b2399f931 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -395,30 +395,7 @@ public class Suggest implements Dictionary.WordCallback { final ArrayList suggestionsList; if (DBG) { - // TODO: this doesn't take into account the fact that removing dupes from mSuggestions - // may have made mScores[] and mSuggestions out of sync. - final CharSequence autoCorrectionSuggestion = mSuggestions.get(0); - double normalizedScore = BinaryDictionary.calcNormalizedScore( - typedWord, autoCorrectionSuggestion.toString(), mScores[0]); - final int suggestionsSize = mSuggestions.size(); - suggestionsList = new ArrayList(suggestionsSize); - suggestionsList.add(new SuggestedWordInfo(autoCorrectionSuggestion, "+", false)); - // Note: i here is the index in mScores[], but the index in mSuggestions is one more - // than i because we added the typed word to mSuggestions without touching mScores. - for (int i = 0; i < mScores.length && i < suggestionsSize - 1; ++i) { - final String scoreInfoString; - if (normalizedScore > 0) { - scoreInfoString = String.format("%d (%4.2f)", mScores[i], normalizedScore); - normalizedScore = 0.0; - } else { - scoreInfoString = Integer.toString(mScores[i]); - } - suggestionsList.add(new SuggestedWordInfo(mSuggestions.get(i + 1), - scoreInfoString, false)); - } - for (int i = mScores.length; i < suggestionsSize; ++i) { - suggestionsList.add(new SuggestedWordInfo(mSuggestions.get(i), "--", false)); - } + suggestionsList = getSuggestionsInfoListWithDebugInfo(typedWord, mSuggestions, mScores); } else { suggestionsList = SuggestedWords.getFromCharSequenceList(mSuggestions); } @@ -446,6 +423,37 @@ public class Suggest implements Dictionary.WordCallback { false /* isPunctuationSuggestions */); } + // This assumes the scores[] array is at least as long as suggestions.size() - 1. + private static ArrayList getSuggestionsInfoListWithDebugInfo( + final String typedWord, final ArrayList suggestions, final int[] scores) { + // TODO: this doesn't take into account the fact that removing dupes from mSuggestions + // may have made mScores[] and mSuggestions out of sync. + final CharSequence autoCorrectionSuggestion = suggestions.get(0); + double normalizedScore = BinaryDictionary.calcNormalizedScore( + typedWord, autoCorrectionSuggestion.toString(), scores[0]); + final int suggestionsSize = suggestions.size(); + final ArrayList suggestionsList = + new ArrayList(suggestionsSize); + suggestionsList.add(new SuggestedWordInfo(autoCorrectionSuggestion, "+", false)); + // Note: i here is the index in mScores[], but the index in mSuggestions is one more + // than i because we added the typed word to mSuggestions without touching mScores. + for (int i = 0; i < scores.length && i < suggestionsSize - 1; ++i) { + final String scoreInfoString; + if (normalizedScore > 0) { + scoreInfoString = String.format("%d (%4.2f)", scores[i], normalizedScore); + normalizedScore = 0.0; + } else { + scoreInfoString = Integer.toString(scores[i]); + } + suggestionsList.add(new SuggestedWordInfo(suggestions.get(i + 1), + scoreInfoString, false)); + } + for (int i = scores.length; i < suggestionsSize; ++i) { + suggestionsList.add(new SuggestedWordInfo(suggestions.get(i), "--", false)); + } + return suggestionsList; + } + @Override public boolean addWord(final char[] word, final int offset, final int length, int score, final int dicTypeId, final int dataType) {