diff --git a/src/com/android/inputmethod/latin/Suggest.java b/src/com/android/inputmethod/latin/Suggest.java index bb6a153dc..c025566b7 100755 --- a/src/com/android/inputmethod/latin/Suggest.java +++ b/src/com/android/inputmethod/latin/Suggest.java @@ -48,9 +48,9 @@ public class Suggest implements Dictionary.WordCallback { private int mPrefMaxSuggestions = 12; private int[] mPriorities = new int[mPrefMaxSuggestions]; - private List mSuggestions = new ArrayList(); + private ArrayList mSuggestions = new ArrayList(); private boolean mIncludeTypedWordIfValid; - private List mStringPool = new ArrayList(); + private ArrayList mStringPool = new ArrayList(); private Context mContext; private boolean mHaveCorrection; private CharSequence mOriginalWord; @@ -218,10 +218,38 @@ public class Suggest implements Dictionary.WordCallback { } i++; } - + + removeDupes(); return mSuggestions; } + private void removeDupes() { + final ArrayList suggestions = mSuggestions; + if (suggestions.size() < 2) return; + int i = 1; + // Don't cache suggestions.size(), since we may be removing items + while (i < suggestions.size()) { + final CharSequence cur = suggestions.get(i); + // Compare each candidate with each previous candidate + for (int j = 0; j < i; j++) { + CharSequence previous = suggestions.get(j); + if (TextUtils.equals(cur, previous)) { + removeFromSuggestions(i); + i--; + break; + } + } + i++; + } + } + + private void removeFromSuggestions(int index) { + CharSequence garbage = mSuggestions.remove(index); + if (garbage != null && garbage instanceof StringBuilder) { + mStringPool.add(garbage); + } + } + public boolean hasMinimalCorrection() { return mHaveCorrection; }