From 7c9bff96f0bbc237c9e4cbe86a409b93555cf33a Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 13 Mar 2012 14:18:30 +0900 Subject: [PATCH] Kill methods with side-effects, take 2 ...working this time Change-Id: I80e377e6250d3817f1e067a551bca2a557740764 --- .../inputmethod/latin/SettingsValues.java | 21 ++++++++++++------- .../inputmethod/latin/SuggestedWords.java | 15 ++----------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index abd1dc692..1f4909f73 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -28,6 +28,7 @@ import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.compat.VibratorCompatWrapper; import com.android.inputmethod.keyboard.internal.KeySpecParser; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -174,28 +175,34 @@ public class SettingsValues { } private static SuggestedWords createSuggestPuncList(final String[] puncs) { - final SuggestedWords.Builder builder = new SuggestedWords.Builder(); + final ArrayList puncList = new ArrayList(); if (puncs != null) { for (final String puncSpec : puncs) { - builder.addWord(KeySpecParser.getLabel(puncSpec)); + puncList.add(KeySpecParser.getLabel(puncSpec)); } } - return builder.setIsPunctuationSuggestions().build(); + final SuggestedWords.Builder builder = new SuggestedWords.Builder() + .addWords(puncList, null) + .setIsPunctuationSuggestions(); + return builder.build(); } private static SuggestedWords createSuggestPuncOutputTextList(final String[] puncs) { - final SuggestedWords.Builder builder = new SuggestedWords.Builder(); + final ArrayList puncOutputTextList = new ArrayList(); if (puncs != null) { for (final String puncSpec : puncs) { final String outputText = KeySpecParser.getOutputText(puncSpec); if (outputText != null) { - builder.addWord(outputText); + puncOutputTextList.add(outputText); } else { - builder.addWord(KeySpecParser.getLabel(puncSpec)); + puncOutputTextList.add(KeySpecParser.getLabel(puncSpec)); } } } - return builder.setIsPunctuationSuggestions().build(); + final SuggestedWords.Builder builder = new SuggestedWords.Builder() + .addWords(puncOutputTextList, null) + .setIsPunctuationSuggestions(); + return builder.build(); } private static String createWordSeparators(final String weakSpaceStrippers, diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 4a51e796d..9959292cb 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -104,17 +104,6 @@ public class SuggestedWords { return this; } - public Builder addWord(CharSequence word) { - return addWord(word, null, false); - } - - public Builder addWord(CharSequence word, CharSequence debugString, - boolean isPreviousSuggestedWord) { - SuggestedWordInfo info = new SuggestedWordInfo(word, debugString, - isPreviousSuggestedWord); - return addWord(word, info); - } - /* package for tests */ Builder addWord(CharSequence word, SuggestedWordInfo suggestedWordInfo) { if (!TextUtils.isEmpty(suggestedWordInfo.mWord)) { @@ -169,14 +158,14 @@ public class SuggestedWords { SuggestedWords previousSuggestions) { mSuggestedWordInfoList.clear(); final HashSet alreadySeen = new HashSet(); - addWord(typedWord, null, false); + addWord(typedWord, new SuggestedWordInfo(typedWord, null, false)); alreadySeen.add(typedWord.toString()); final int previousSize = previousSuggestions.size(); for (int pos = 1; pos < previousSize; pos++) { final String prevWord = previousSuggestions.getWord(pos).toString(); // Filter out duplicate suggestion. if (!alreadySeen.contains(prevWord)) { - addWord(prevWord, null, true); + addWord(prevWord, new SuggestedWordInfo(prevWord, null, true)); alreadySeen.add(prevWord); } }