From 674ffcdf9361b3c90cc39daf02f3217fb6d870de Mon Sep 17 00:00:00 2001
From: Jean Chalard <jchalard@google.com>
Date: Tue, 13 Mar 2012 16:36:21 +0900
Subject: [PATCH] Make an add into a set.

This method now only sets words, so it should be named set.
The functionality is identical since there are no more places
where the list is reused.
This will also allow to make the list final in an upcoming change.

Change-Id: I25b0c7d7f13c3fa5d89806f01f48f1026769603f
---
 java/src/com/android/inputmethod/latin/LatinIME.java  |  4 ++--
 .../com/android/inputmethod/latin/SettingsValues.java |  4 ++--
 java/src/com/android/inputmethod/latin/Suggest.java   |  6 +++---
 .../com/android/inputmethod/latin/SuggestedWords.java | 11 ++++++-----
 4 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 39cbfa7a02..a7985c37d0 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -927,7 +927,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
                     SuggestedWords.Builder.getFromApplicationSpecifiedCompletions(
                             applicationSpecifiedCompletions);
             SuggestedWords.Builder builder = new SuggestedWords.Builder()
-                    .addWords(applicationSuggestedWords)
+                    .setWords(applicationSuggestedWords)
                     .setTypedWordValid(false)
                     .setHasMinimalSuggestion(false);
             // When in fullscreen mode, show completions generated by the application
@@ -1787,7 +1787,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
                     SuggestedWords.Builder.getTypedWordAndPreviousSuggestions(
                             typedWord, previousSuggestions);
             final SuggestedWords.Builder obsoleteSuggestionsBuilder = new SuggestedWords.Builder()
-                    .addWords(typedWordAndPreviousSuggestions)
+                    .setWords(typedWordAndPreviousSuggestions)
                     .setTypedWordValid(false)
                     .setHasMinimalSuggestion(false);
 
diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java
index 7e7702002d..9abea66b2a 100644
--- a/java/src/com/android/inputmethod/latin/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/SettingsValues.java
@@ -184,7 +184,7 @@ public class SettingsValues {
             }
         }
         final SuggestedWords.Builder builder = new SuggestedWords.Builder()
-                .addWords(puncList)
+                .setWords(puncList)
                 .setIsPunctuationSuggestions();
         return builder.build();
     }
@@ -204,7 +204,7 @@ public class SettingsValues {
             }
         }
         final SuggestedWords.Builder builder = new SuggestedWords.Builder()
-                .addWords(puncOutputTextList)
+                .setWords(puncOutputTextList)
                 .setIsPunctuationSuggestions();
         return builder.build();
     }
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 487e91b0e2..a5c70eca99 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -270,7 +270,7 @@ public class Suggest implements Dictionary.WordCallback {
         StringUtils.removeDupes(mSuggestions);
 
         return new SuggestedWords.Builder()
-                .addWords(SuggestedWords.Builder.getFromCharSequenceList(mSuggestions))
+                .setWords(SuggestedWords.Builder.getFromCharSequenceList(mSuggestions))
                 .setAllowsToBeAutoCorrected(false)
                 .setHasAutoCorrection(false);
     }
@@ -424,12 +424,12 @@ public class Suggest implements Dictionary.WordCallback {
                 scoreInfoList.add(new SuggestedWords.SuggestedWordInfo(mSuggestions.get(i),
                         "--", false));
             }
-            builder = new SuggestedWords.Builder().addWords(scoreInfoList)
+            builder = new SuggestedWords.Builder().setWords(scoreInfoList)
                     .setAllowsToBeAutoCorrected(allowsToBeAutoCorrected)
                     .setHasAutoCorrection(hasAutoCorrection);
         } else {
             builder = new SuggestedWords.Builder()
-                    .addWords(SuggestedWords.Builder.getFromCharSequenceList(mSuggestions))
+                    .setWords(SuggestedWords.Builder.getFromCharSequenceList(mSuggestions))
                     .setAllowsToBeAutoCorrected(allowsToBeAutoCorrected)
                     .setHasAutoCorrection(hasAutoCorrection);
         }
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java
index 9a7ea6b6a8..5d0fc20b20 100644
--- a/java/src/com/android/inputmethod/latin/SuggestedWords.java
+++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java
@@ -87,12 +87,13 @@ public class SuggestedWords {
             // Nothing to do here.
         }
 
+        // TODO: compatibility for tests. Remove this once tests are okay.
         public Builder addWords(List<SuggestedWordInfo> suggestedWordInfoList) {
-            final int N = suggestedWordInfoList.size();
-            for (int i = 0; i < N; ++i) {
-                SuggestedWordInfo suggestedWordInfo = suggestedWordInfoList.get(i);
-                addWord(suggestedWordInfo.mWord, suggestedWordInfo);
-            }
+            return setWords(suggestedWordInfoList);
+        }
+
+        public Builder setWords(List<SuggestedWordInfo> suggestedWordInfoList) {
+            mSuggestedWordInfoList = suggestedWordInfoList;
             return this;
         }
 
-- 
GitLab