Simplify a method call.

Change-Id: Ieede787a13cef79353f13af52488ef3732ac9850
main
Jean Chalard 2012-06-26 19:20:20 +09:00
parent 9433ce86b7
commit bed514bd90
1 changed files with 21 additions and 24 deletions

View File

@ -222,7 +222,7 @@ public class Suggest {
mIsFirstCharCapitalized = !isPrediction && wordComposer.isFirstCharCapitalized(); mIsFirstCharCapitalized = !isPrediction && wordComposer.isFirstCharCapitalized();
mIsAllUpperCase = !isPrediction && wordComposer.isAllUpperCase(); mIsAllUpperCase = !isPrediction && wordComposer.isAllUpperCase();
mTrailingSingleQuotesCount = wordComposer.trailingSingleQuotesCount(); mTrailingSingleQuotesCount = wordComposer.trailingSingleQuotesCount();
final ArrayList<SuggestedWordInfo> suggestions = final ArrayList<SuggestedWordInfo> suggestionsContainer =
new ArrayList<SuggestedWordInfo>(MAX_SUGGESTIONS); new ArrayList<SuggestedWordInfo>(MAX_SUGGESTIONS);
final String typedWord = wordComposer.getTypedWord(); final String typedWord = wordComposer.getTypedWord();
@ -250,11 +250,9 @@ public class Suggest {
if (null != lowerPrevWord) { if (null != lowerPrevWord) {
localSuggestions.addAll(dictionary.getBigrams(wordComposer, lowerPrevWord)); localSuggestions.addAll(dictionary.getBigrams(wordComposer, lowerPrevWord));
} }
for (final SuggestedWordInfo suggestion : localSuggestions) { for (final SuggestedWordInfo localSuggestion : localSuggestions) {
final String suggestionStr = suggestion.mWord.toString(); addWord(localSuggestion, dicTypeId, Dictionary.BIGRAM,
addWord(suggestionStr, null, suggestionsContainer, consideredWord);
suggestion.mScore, dicTypeId, Dictionary.BIGRAM,
suggestions, consideredWord);
} }
} }
} }
@ -278,10 +276,8 @@ public class Suggest {
final ArrayList<SuggestedWordInfo> localSuggestions = dictionary.getWords( final ArrayList<SuggestedWordInfo> localSuggestions = dictionary.getWords(
wordComposerForLookup, prevWordForBigram, proximityInfo); wordComposerForLookup, prevWordForBigram, proximityInfo);
for (final SuggestedWordInfo suggestion : localSuggestions) { for (final SuggestedWordInfo suggestion : localSuggestions) {
final String suggestionStr = suggestion.mWord.toString(); addWord(suggestion, dicTypeId, Dictionary.UNIGRAM,
addWord(suggestionStr, null, suggestionsContainer, consideredWord);
suggestion.mScore, dicTypeId, Dictionary.UNIGRAM,
suggestions, consideredWord);
} }
} }
} }
@ -293,7 +289,7 @@ public class Suggest {
if (isCorrectionEnabled) { if (isCorrectionEnabled) {
final CharSequence autoCorrection = final CharSequence autoCorrection =
AutoCorrection.computeAutoCorrectionWord(mDictionaries, wordComposer, AutoCorrection.computeAutoCorrectionWord(mDictionaries, wordComposer,
suggestions, consideredWord, mAutoCorrectionThreshold, suggestionsContainer, consideredWord, mAutoCorrectionThreshold,
whitelistedWord); whitelistedWord);
hasAutoCorrection = (null != autoCorrection); hasAutoCorrection = (null != autoCorrection);
} else { } else {
@ -306,25 +302,25 @@ public class Suggest {
for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) { for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) {
sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE); sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE);
} }
suggestions.add(0, new SuggestedWordInfo(sb.toString(), suggestionsContainer.add(0, new SuggestedWordInfo(sb.toString(),
SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_WHITELIST)); SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_WHITELIST));
} else { } else {
suggestions.add(0, new SuggestedWordInfo(whitelistedWord, suggestionsContainer.add(0, new SuggestedWordInfo(whitelistedWord,
SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_WHITELIST)); SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_WHITELIST));
} }
} }
if (!isPrediction) { if (!isPrediction) {
suggestions.add(0, new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE, suggestionsContainer.add(0, new SuggestedWordInfo(typedWord,
SuggestedWordInfo.KIND_TYPED)); SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_TYPED));
} }
SuggestedWordInfo.removeDups(suggestions); SuggestedWordInfo.removeDups(suggestionsContainer);
final ArrayList<SuggestedWordInfo> suggestionsList; final ArrayList<SuggestedWordInfo> suggestionsList;
if (DBG && !suggestions.isEmpty()) { if (DBG && !suggestionsContainer.isEmpty()) {
suggestionsList = getSuggestionsInfoListWithDebugInfo(typedWord, suggestions); suggestionsList = getSuggestionsInfoListWithDebugInfo(typedWord, suggestionsContainer);
} else { } else {
suggestionsList = suggestions; suggestionsList = suggestionsContainer;
} }
// TODO: Change this scheme - a boolean is not enough. A whitelisted word may be "valid" // TODO: Change this scheme - a boolean is not enough. A whitelisted word may be "valid"
@ -388,13 +384,14 @@ public class Suggest {
return suggestionsList; return suggestionsList;
} }
public boolean addWord(final String word, int[] indices, public boolean addWord(final SuggestedWordInfo wordInfo,
int score, final int dicTypeId, final int dataType, final int dicTypeId, final int dataType,
final ArrayList<SuggestedWordInfo> suggestions, final String consideredWord) { final ArrayList<SuggestedWordInfo> suggestions, final String consideredWord) {
int dataTypeForLog = dataType; int dataTypeForLog = dataType;
final int prefMaxSuggestions = MAX_SUGGESTIONS; final int prefMaxSuggestions = MAX_SUGGESTIONS;
final int length = word.codePointCount(0, word.length());
final String word = wordInfo.mWord.toString();
final int score = wordInfo.mScore;
int pos = 0; int pos = 0;
// Check if it's the same word, only caps are different // Check if it's the same word, only caps are different
@ -416,6 +413,7 @@ public class Suggest {
// Check the last one's score and bail // Check the last one's score and bail
if (suggestions.size() >= prefMaxSuggestions if (suggestions.size() >= prefMaxSuggestions
&& suggestions.get(prefMaxSuggestions - 1).mScore >= score) return true; && suggestions.get(prefMaxSuggestions - 1).mScore >= score) return true;
final int length = word.codePointCount(0, word.length());
while (pos < suggestions.size()) { while (pos < suggestions.size()) {
final int curScore = suggestions.get(pos).mScore; final int curScore = suggestions.get(pos).mScore;
if (curScore < score if (curScore < score
@ -440,8 +438,7 @@ public class Suggest {
for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) { for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) {
sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE); sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE);
} }
// TODO: figure out what type of suggestion this is suggestions.add(pos, new SuggestedWordInfo(sb, score, wordInfo.mKind));
suggestions.add(pos, new SuggestedWordInfo(sb, score, SuggestedWordInfo.KIND_CORRECTION));
if (suggestions.size() > prefMaxSuggestions) { if (suggestions.size() > prefMaxSuggestions) {
suggestions.remove(prefMaxSuggestions); suggestions.remove(prefMaxSuggestions);
} else { } else {