am d8b3e5c6: am 0c207144: Merge "Fix a bug with a concurrent modification of a map." into jb-dev

* commit 'd8b3e5c69f4de663c748c82155fc3b8854119826':
  Fix a bug with a concurrent modification of a map.
main
Jean Chalard 2012-05-24 03:44:06 -07:00 committed by Android Git Automerger
commit 5ea26193a2
2 changed files with 21 additions and 18 deletions

View File

@ -22,7 +22,7 @@ import android.text.TextUtils;
import android.util.Log;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
public class AutoCorrection {
private static final boolean DBG = LatinImeLogger.sDBG;
@ -33,10 +33,10 @@ public class AutoCorrection {
}
public static CharSequence computeAutoCorrectionWord(
HashMap<String, Dictionary> dictionaries,
WordComposer wordComposer, ArrayList<SuggestedWordInfo> suggestions,
CharSequence consideredWord, float autoCorrectionThreshold,
CharSequence whitelistedWord) {
final ConcurrentHashMap<String, Dictionary> dictionaries,
final WordComposer wordComposer, final ArrayList<SuggestedWordInfo> suggestions,
final CharSequence consideredWord, final float autoCorrectionThreshold,
final CharSequence whitelistedWord) {
if (hasAutoCorrectionForWhitelistedWord(whitelistedWord)) {
return whitelistedWord;
} else if (hasAutoCorrectionForConsideredWord(
@ -49,8 +49,8 @@ public class AutoCorrection {
return null;
}
public static boolean isValidWord(
HashMap<String, Dictionary> dictionaries, CharSequence word, boolean ignoreCase) {
public static boolean isValidWord(final ConcurrentHashMap<String, Dictionary> dictionaries,
CharSequence word, boolean ignoreCase) {
if (TextUtils.isEmpty(word)) {
return false;
}
@ -75,7 +75,8 @@ public class AutoCorrection {
}
public static boolean allowsToBeAutoCorrected(
HashMap<String, Dictionary> dictionaries, CharSequence word, boolean ignoreCase) {
final ConcurrentHashMap<String, Dictionary> dictionaries,
final CharSequence word, final boolean ignoreCase) {
final WhitelistDictionary whitelistDictionary =
(WhitelistDictionary)dictionaries.get(Suggest.DICT_KEY_WHITELIST);
// If "word" is in the whitelist dictionary, it should not be auto corrected.
@ -91,8 +92,9 @@ public class AutoCorrection {
}
private static boolean hasAutoCorrectionForConsideredWord(
HashMap<String, Dictionary> dictionaries, WordComposer wordComposer,
ArrayList<SuggestedWordInfo> suggestions, CharSequence consideredWord) {
final ConcurrentHashMap<String, Dictionary> dictionaries,
final WordComposer wordComposer, final ArrayList<SuggestedWordInfo> suggestions,
final CharSequence consideredWord) {
if (TextUtils.isEmpty(consideredWord)) return false;
return wordComposer.size() > 1 && suggestions.size() > 0
&& !allowsToBeAutoCorrected(dictionaries, consideredWord, false);

View File

@ -26,9 +26,9 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.concurrent.ConcurrentHashMap;
/**
* This class loads a dictionary and provides a list of suggestions for a given sequence of
@ -68,10 +68,10 @@ public class Suggest implements Dictionary.WordCallback {
private boolean mHasMainDictionary;
private Dictionary mContactsDict;
private WhitelistDictionary mWhiteListDictionary;
private final HashMap<String, Dictionary> mUnigramDictionaries =
new HashMap<String, Dictionary>();
private final HashMap<String, Dictionary> mBigramDictionaries =
new HashMap<String, Dictionary>();
private final ConcurrentHashMap<String, Dictionary> mUnigramDictionaries =
new ConcurrentHashMap<String, Dictionary>();
private final ConcurrentHashMap<String, Dictionary> mBigramDictionaries =
new ConcurrentHashMap<String, Dictionary>();
private int mPrefMaxSuggestions = 18;
@ -117,8 +117,9 @@ public class Suggest implements Dictionary.WordCallback {
initWhitelistAndAutocorrectAndPool(context, locale);
}
private static void addOrReplaceDictionary(HashMap<String, Dictionary> dictionaries, String key,
Dictionary dict) {
private static void addOrReplaceDictionary(
final ConcurrentHashMap<String, Dictionary> dictionaries,
final String key, final Dictionary dict) {
final Dictionary oldDict = (dict == null)
? dictionaries.remove(key)
: dictionaries.put(key, dict);
@ -151,7 +152,7 @@ public class Suggest implements Dictionary.WordCallback {
return mContactsDict;
}
public HashMap<String, Dictionary> getUnigramDictionaries() {
public ConcurrentHashMap<String, Dictionary> getUnigramDictionaries() {
return mUnigramDictionaries;
}