aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2012-03-14 18:47:26 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-03-14 18:47:26 -0700
commitc787db51eddf6560530672243f747ae01cea2c13 (patch)
treeb4e182dddbaff3a401bb6ad1302bb51f0d202768 /java/src
parentb9a5cb77f0bd2a360e921cc212cc81ae2528cdbf (diff)
parent0d0f182959600d83c376e6b844337ea45e5ddbbf (diff)
downloadlatinime-c787db51eddf6560530672243f747ae01cea2c13.tar.gz
latinime-c787db51eddf6560530672243f747ae01cea2c13.tar.xz
latinime-c787db51eddf6560530672243f747ae01cea2c13.zip
Merge "Cut out a private method to make things more readable"
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java56
1 files 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<SuggestedWordInfo> 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<SuggestedWordInfo>(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<SuggestedWordInfo> getSuggestionsInfoListWithDebugInfo(
+ final String typedWord, final ArrayList<CharSequence> 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<SuggestedWordInfo> suggestionsList =
+ new ArrayList<SuggestedWordInfo>(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) {