Kill methods with side-effects, take 2

...working this time

Change-Id: I80e377e6250d3817f1e067a551bca2a557740764
main
Jean Chalard 2012-03-13 14:18:30 +09:00
parent 041c3d3841
commit 7c9bff96f0
2 changed files with 16 additions and 20 deletions

View File

@ -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<CharSequence> puncList = new ArrayList<CharSequence>();
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<CharSequence> puncOutputTextList = new ArrayList<CharSequence>();
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,

View File

@ -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<String> alreadySeen = new HashSet<String>();
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);
}
}