aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod')
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java4
-rw-r--r--java/src/com/android/inputmethod/latin/SuggestedWords.java37
2 files changed, 21 insertions, 20 deletions
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 7364fc979..575ec5c76 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -180,6 +180,7 @@ public final class Suggest {
suggestionsContainer.set(i, transformedWordInfo);
}
}
+ SuggestedWordInfo.removeDups(typedWord, suggestionsContainer);
if (!TextUtils.isEmpty(typedWord)) {
suggestionsContainer.add(0, new SuggestedWordInfo(typedWord,
@@ -188,7 +189,6 @@ public final class Suggest {
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */,
SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */));
}
- SuggestedWordInfo.removeDups(suggestionsContainer);
final ArrayList<SuggestedWordInfo> suggestionsList;
if (DBG && !suggestionsContainer.isEmpty()) {
@@ -237,7 +237,7 @@ public final class Suggest {
final SuggestedWordInfo rejected = suggestionsContainer.remove(0);
suggestionsContainer.add(1, rejected);
}
- SuggestedWordInfo.removeDups(suggestionsContainer);
+ SuggestedWordInfo.removeDups(null /* typedWord */, suggestionsContainer);
// For some reason some suggestions with MIN_VALUE are making their way here.
// TODO: Find a more robust way to detect distractors.
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java
index 72461e17a..8e78e970f 100644
--- a/java/src/com/android/inputmethod/latin/SuggestedWords.java
+++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java
@@ -316,10 +316,6 @@ public class SuggestedWords {
return mDebugString;
}
- public int codePointCount() {
- return mCodePointCount;
- }
-
public int codePointAt(int i) {
return mWord.codePointAt(i);
}
@@ -333,23 +329,28 @@ public class SuggestedWords {
}
}
- // TODO: Consolidate this method and StringUtils.removeDupes() in the future.
- public static void removeDups(ArrayList<SuggestedWordInfo> candidates) {
- if (candidates.size() <= 1) {
+ // This will always remove the higher index if a duplicate is found.
+ public static void removeDups(final String typedWord,
+ ArrayList<SuggestedWordInfo> candidates) {
+ if (candidates.isEmpty()) {
return;
}
- int i = 1;
- while (i < candidates.size()) {
- final SuggestedWordInfo cur = candidates.get(i);
- for (int j = 0; j < i; ++j) {
- final SuggestedWordInfo previous = candidates.get(j);
- if (cur.mWord.equals(previous.mWord)) {
- candidates.remove(cur.mScore < previous.mScore ? i : j);
- --i;
- break;
- }
+ if (!TextUtils.isEmpty(typedWord)) {
+ removeSuggestedWordInfoFrom(typedWord, candidates, 0);
+ }
+ for (int i = 0; i < candidates.size(); ++i) {
+ removeSuggestedWordInfoFrom(candidates.get(i).mWord, candidates, i);
+ }
+ }
+
+ private static void removeSuggestedWordInfoFrom(final String word,
+ final ArrayList<SuggestedWordInfo> candidates, final int startIndex) {
+ for (int i = startIndex + 1; i < candidates.size(); ++i) {
+ final SuggestedWordInfo previous = candidates.get(i);
+ if (word.equals(previous.mWord)) {
+ candidates.remove(i);
+ --i;
}
- ++i;
}
}
}