* commit 'd8b3e5c69f4de663c748c82155fc3b8854119826': Fix a bug with a concurrent modification of a map.
This commit is contained in:
commit
5ea26193a2
2 changed files with 21 additions and 18 deletions
|
@ -22,7 +22,7 @@ import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class AutoCorrection {
|
public class AutoCorrection {
|
||||||
private static final boolean DBG = LatinImeLogger.sDBG;
|
private static final boolean DBG = LatinImeLogger.sDBG;
|
||||||
|
@ -33,10 +33,10 @@ public class AutoCorrection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CharSequence computeAutoCorrectionWord(
|
public static CharSequence computeAutoCorrectionWord(
|
||||||
HashMap<String, Dictionary> dictionaries,
|
final ConcurrentHashMap<String, Dictionary> dictionaries,
|
||||||
WordComposer wordComposer, ArrayList<SuggestedWordInfo> suggestions,
|
final WordComposer wordComposer, final ArrayList<SuggestedWordInfo> suggestions,
|
||||||
CharSequence consideredWord, float autoCorrectionThreshold,
|
final CharSequence consideredWord, final float autoCorrectionThreshold,
|
||||||
CharSequence whitelistedWord) {
|
final CharSequence whitelistedWord) {
|
||||||
if (hasAutoCorrectionForWhitelistedWord(whitelistedWord)) {
|
if (hasAutoCorrectionForWhitelistedWord(whitelistedWord)) {
|
||||||
return whitelistedWord;
|
return whitelistedWord;
|
||||||
} else if (hasAutoCorrectionForConsideredWord(
|
} else if (hasAutoCorrectionForConsideredWord(
|
||||||
|
@ -49,8 +49,8 @@ public class AutoCorrection {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValidWord(
|
public static boolean isValidWord(final ConcurrentHashMap<String, Dictionary> dictionaries,
|
||||||
HashMap<String, Dictionary> dictionaries, CharSequence word, boolean ignoreCase) {
|
CharSequence word, boolean ignoreCase) {
|
||||||
if (TextUtils.isEmpty(word)) {
|
if (TextUtils.isEmpty(word)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,8 @@ public class AutoCorrection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean allowsToBeAutoCorrected(
|
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 =
|
final WhitelistDictionary whitelistDictionary =
|
||||||
(WhitelistDictionary)dictionaries.get(Suggest.DICT_KEY_WHITELIST);
|
(WhitelistDictionary)dictionaries.get(Suggest.DICT_KEY_WHITELIST);
|
||||||
// If "word" is in the whitelist dictionary, it should not be auto corrected.
|
// If "word" is in the whitelist dictionary, it should not be auto corrected.
|
||||||
|
@ -91,8 +92,9 @@ public class AutoCorrection {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean hasAutoCorrectionForConsideredWord(
|
private static boolean hasAutoCorrectionForConsideredWord(
|
||||||
HashMap<String, Dictionary> dictionaries, WordComposer wordComposer,
|
final ConcurrentHashMap<String, Dictionary> dictionaries,
|
||||||
ArrayList<SuggestedWordInfo> suggestions, CharSequence consideredWord) {
|
final WordComposer wordComposer, final ArrayList<SuggestedWordInfo> suggestions,
|
||||||
|
final CharSequence consideredWord) {
|
||||||
if (TextUtils.isEmpty(consideredWord)) return false;
|
if (TextUtils.isEmpty(consideredWord)) return false;
|
||||||
return wordComposer.size() > 1 && suggestions.size() > 0
|
return wordComposer.size() > 1 && suggestions.size() > 0
|
||||||
&& !allowsToBeAutoCorrected(dictionaries, consideredWord, false);
|
&& !allowsToBeAutoCorrected(dictionaries, consideredWord, false);
|
||||||
|
|
|
@ -26,9 +26,9 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Locale;
|
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
|
* 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 boolean mHasMainDictionary;
|
||||||
private Dictionary mContactsDict;
|
private Dictionary mContactsDict;
|
||||||
private WhitelistDictionary mWhiteListDictionary;
|
private WhitelistDictionary mWhiteListDictionary;
|
||||||
private final HashMap<String, Dictionary> mUnigramDictionaries =
|
private final ConcurrentHashMap<String, Dictionary> mUnigramDictionaries =
|
||||||
new HashMap<String, Dictionary>();
|
new ConcurrentHashMap<String, Dictionary>();
|
||||||
private final HashMap<String, Dictionary> mBigramDictionaries =
|
private final ConcurrentHashMap<String, Dictionary> mBigramDictionaries =
|
||||||
new HashMap<String, Dictionary>();
|
new ConcurrentHashMap<String, Dictionary>();
|
||||||
|
|
||||||
private int mPrefMaxSuggestions = 18;
|
private int mPrefMaxSuggestions = 18;
|
||||||
|
|
||||||
|
@ -117,8 +117,9 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
initWhitelistAndAutocorrectAndPool(context, locale);
|
initWhitelistAndAutocorrectAndPool(context, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addOrReplaceDictionary(HashMap<String, Dictionary> dictionaries, String key,
|
private static void addOrReplaceDictionary(
|
||||||
Dictionary dict) {
|
final ConcurrentHashMap<String, Dictionary> dictionaries,
|
||||||
|
final String key, final Dictionary dict) {
|
||||||
final Dictionary oldDict = (dict == null)
|
final Dictionary oldDict = (dict == null)
|
||||||
? dictionaries.remove(key)
|
? dictionaries.remove(key)
|
||||||
: dictionaries.put(key, dict);
|
: dictionaries.put(key, dict);
|
||||||
|
@ -151,7 +152,7 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
return mContactsDict;
|
return mContactsDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, Dictionary> getUnigramDictionaries() {
|
public ConcurrentHashMap<String, Dictionary> getUnigramDictionaries() {
|
||||||
return mUnigramDictionaries;
|
return mUnigramDictionaries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue