diff options
author | 2015-02-26 03:48:37 +0000 | |
---|---|---|
committer | 2015-02-26 03:48:37 +0000 | |
commit | 458cc72c15bbccf6ca709c4e2bfdc2c10b3c2715 (patch) | |
tree | c4a8cface9f980a7edd1841afc767136de10b62e /java/src/com/android/inputmethod/latin/SuggestedWords.java | |
parent | d11e4cd964a0be64efd415e6f5f2ca1c14d435de (diff) | |
parent | e4619f029e84fd845b0771871218274b99c30ffa (diff) | |
download | latinime-458cc72c15bbccf6ca709c4e2bfdc2c10b3c2715.tar.gz latinime-458cc72c15bbccf6ca709c4e2bfdc2c10b3c2715.tar.xz latinime-458cc72c15bbccf6ca709c4e2bfdc2c10b3c2715.zip |
am e4619f02: Merge "Don\'t assume that correctable words are invalid"
* commit 'e4619f029e84fd845b0771871218274b99c30ffa':
Don't assume that correctable words are invalid
Diffstat (limited to 'java/src/com/android/inputmethod/latin/SuggestedWords.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/SuggestedWords.java | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 913b63a61..3816c0870 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -17,6 +17,7 @@ package com.android.inputmethod.latin; import android.text.TextUtils; +import android.util.Log; import android.view.inputmethod.CompletionInfo; import com.android.inputmethod.annotations.UsedForTesting; @@ -375,31 +376,45 @@ public class SuggestedWords { return mWord + " (" + mDebugString + ")"; } - // This will always remove the higher index if a duplicate is found. - public static void removeDups(@Nullable final String typedWord, - @Nonnull ArrayList<SuggestedWordInfo> candidates) { + /** + * This will always remove the higher index if a duplicate is found. + * + * @return position of typed word in the candidate list + */ + public static int removeDups( + @Nullable final String typedWord, + @Nonnull final ArrayList<SuggestedWordInfo> candidates) { if (candidates.isEmpty()) { - return; + return -1; } + int firstOccurrenceOfWord = -1; if (!TextUtils.isEmpty(typedWord)) { - removeSuggestedWordInfoFromList(typedWord, candidates, -1 /* startIndexExclusive */); + firstOccurrenceOfWord = removeSuggestedWordInfoFromList( + typedWord, candidates, -1 /* startIndexExclusive */); } for (int i = 0; i < candidates.size(); ++i) { - removeSuggestedWordInfoFromList(candidates.get(i).mWord, candidates, - i /* startIndexExclusive */); + removeSuggestedWordInfoFromList( + candidates.get(i).mWord, candidates, i /* startIndexExclusive */); } + return firstOccurrenceOfWord; } - private static void removeSuggestedWordInfoFromList( - @Nonnull final String word, @Nonnull final ArrayList<SuggestedWordInfo> candidates, + private static int removeSuggestedWordInfoFromList( + @Nonnull final String word, + @Nonnull final ArrayList<SuggestedWordInfo> candidates, final int startIndexExclusive) { + int firstOccurrenceOfWord = -1; for (int i = startIndexExclusive + 1; i < candidates.size(); ++i) { final SuggestedWordInfo previous = candidates.get(i); if (word.equals(previous.mWord)) { + if (firstOccurrenceOfWord == -1) { + firstOccurrenceOfWord = i; + } candidates.remove(i); --i; } } + return firstOccurrenceOfWord; } } |