From b26af7eae7747853c1818b3b97f5d1d94b3105ee Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Mon, 12 Mar 2012 19:42:29 -0700 Subject: [PATCH] Revert "Kill methods with side-effects" This reverts commit ca0e04868891c461a3e6f30bf15d209d622c8349 --- .../inputmethod/latin/SettingsValues.java | 21 +++++++------------ .../inputmethod/latin/SuggestedWords.java | 11 ++++++++++ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 1f4909f73..abd1dc692 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -28,7 +28,6 @@ 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; @@ -175,34 +174,28 @@ public class SettingsValues { } private static SuggestedWords createSuggestPuncList(final String[] puncs) { - final ArrayList puncList = new ArrayList(); + final SuggestedWords.Builder builder = new SuggestedWords.Builder(); if (puncs != null) { for (final String puncSpec : puncs) { - puncList.add(KeySpecParser.getLabel(puncSpec)); + builder.addWord(KeySpecParser.getLabel(puncSpec)); } } - final SuggestedWords.Builder builder = new SuggestedWords.Builder() - .addWords(puncList, null) - .setIsPunctuationSuggestions(); - return builder.build(); + return builder.setIsPunctuationSuggestions().build(); } private static SuggestedWords createSuggestPuncOutputTextList(final String[] puncs) { - final ArrayList puncOutputTextList = new ArrayList(); + final SuggestedWords.Builder builder = new SuggestedWords.Builder(); if (puncs != null) { for (final String puncSpec : puncs) { final String outputText = KeySpecParser.getOutputText(puncSpec); if (outputText != null) { - puncOutputTextList.add(outputText); + builder.addWord(outputText); } else { - puncOutputTextList.add(KeySpecParser.getLabel(puncSpec)); + builder.addWord(KeySpecParser.getLabel(puncSpec)); } } } - final SuggestedWords.Builder builder = new SuggestedWords.Builder() - .addWords(puncOutputTextList, null) - .setIsPunctuationSuggestions(); - return builder.build(); + return builder.setIsPunctuationSuggestions().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 a603fd8ec..4a51e796d 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -104,6 +104,17 @@ 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)) {