am 90759f2a: Merge "[CS4] Remove useless tests and processing"

* commit '90759f2ab77e9bb6a47b59e6de89318516a65393':
  [CS4] Remove useless tests and processing
main
Jean Chalard 2014-06-26 09:34:17 +00:00 committed by Android Git Automerger
commit 520605ea31
2 changed files with 21 additions and 26 deletions

View File

@ -123,21 +123,15 @@ public final class Suggest {
suggestionsContainer.set(i, transformedWordInfo); suggestionsContainer.set(i, transformedWordInfo);
} }
} }
SuggestedWordInfo.removeDups(typedWord, suggestionsContainer); final boolean didRemoveTypedWord =
SuggestedWordInfo.removeDups(typedWord, suggestionsContainer);
// If resumed, then we don't want to upcase everything: resuming on a fully-capitalized
// words is rarely done to switch to another fully-capitalized word, but usually to a
// normal, non-capitalized suggestion.
final String firstSuggestion;
final String whitelistedWord; final String whitelistedWord;
if (suggestionResults.isEmpty()) { if (suggestionsContainer.isEmpty()) {
whitelistedWord = firstSuggestion = null; whitelistedWord = firstSuggestion = null;
} else { } else {
final SuggestedWordInfo firstSuggestedWordInfo = getTransformedSuggestedWordInfo( final SuggestedWordInfo firstSuggestedWordInfo = suggestionsContainer.get(0);
suggestionResults.first(), suggestionResults.mLocale, final String firstSuggestion = firstSuggestedWordInfo.mWord;
shouldMakeSuggestionsAllUpperCase, isOnlyFirstCharCapitalized,
trailingSingleQuotesCount);
firstSuggestion = firstSuggestedWordInfo.mWord;
if (!firstSuggestedWordInfo.isKindOf(SuggestedWordInfo.KIND_WHITELIST)) { if (!firstSuggestedWordInfo.isKindOf(SuggestedWordInfo.KIND_WHITELIST)) {
whitelistedWord = null; whitelistedWord = null;
} else { } else {
@ -145,17 +139,10 @@ public final class Suggest {
} }
} }
// We allow auto-correction if we have a whitelisted word, or if the word is not a valid // We allow auto-correction if we have a whitelisted word, or if the word had more than
// word of more than 1 char, except if the first suggestion is the same as the typed string // one char and was not suggested.
// because in this case if it's strong enough to auto-correct that will mistakenly designate final boolean allowsToBeAutoCorrected = (null != whitelistedWord)
// the second candidate for auto-correction. || (consideredWord.length() > 1 && !didRemoveTypedWord);
// TODO: stop relying on indices to find where is the auto-correction in the suggested
// words, and correct this test.
final boolean allowsToBeAutoCorrected = (null != whitelistedWord
&& !whitelistedWord.equals(typedWord))
|| (consideredWord.length() > 1 && !mDictionaryFacilitator.isValidWord(
consideredWord, isOnlyFirstCharCapitalized)
&& !typedWord.equals(firstSuggestion));
final boolean hasAutoCorrection; final boolean hasAutoCorrection;
// TODO: using isCorrectionEnabled here is not very good. It's probably useless, because // TODO: using isCorrectionEnabled here is not very good. It's probably useless, because

View File

@ -330,29 +330,37 @@ public class SuggestedWords {
} }
// This will always remove the higher index if a duplicate is found. // This will always remove the higher index if a duplicate is found.
public static void removeDups(final String typedWord, public static boolean removeDups(final String typedWord,
ArrayList<SuggestedWordInfo> candidates) { ArrayList<SuggestedWordInfo> candidates) {
if (candidates.isEmpty()) { if (candidates.isEmpty()) {
return; return false;
} }
final boolean didRemoveTypedWord;
if (!TextUtils.isEmpty(typedWord)) { if (!TextUtils.isEmpty(typedWord)) {
removeSuggestedWordInfoFrom(typedWord, candidates, -1 /* startIndexExclusive */); didRemoveTypedWord = removeSuggestedWordInfoFrom(typedWord, candidates,
-1 /* startIndexExclusive */);
} else {
didRemoveTypedWord = false;
} }
for (int i = 0; i < candidates.size(); ++i) { for (int i = 0; i < candidates.size(); ++i) {
removeSuggestedWordInfoFrom(candidates.get(i).mWord, candidates, removeSuggestedWordInfoFrom(candidates.get(i).mWord, candidates,
i /* startIndexExclusive */); i /* startIndexExclusive */);
} }
return didRemoveTypedWord;
} }
private static void removeSuggestedWordInfoFrom(final String word, private static boolean removeSuggestedWordInfoFrom(final String word,
final ArrayList<SuggestedWordInfo> candidates, final int startIndexExclusive) { final ArrayList<SuggestedWordInfo> candidates, final int startIndexExclusive) {
boolean didRemove = false;
for (int i = startIndexExclusive + 1; i < candidates.size(); ++i) { for (int i = startIndexExclusive + 1; i < candidates.size(); ++i) {
final SuggestedWordInfo previous = candidates.get(i); final SuggestedWordInfo previous = candidates.get(i);
if (word.equals(previous.mWord)) { if (word.equals(previous.mWord)) {
didRemove = true;
candidates.remove(i); candidates.remove(i);
--i; --i;
} }
} }
return didRemove;
} }
} }