Merge "Add CollectionUtils class to create generic collection easily" into jb-mr1-dev

main
Tadashi G. Takaoka 2012-08-21 20:13:23 -07:00 committed by Android (Google) Code Review
commit eb59a87a07
41 changed files with 215 additions and 114 deletions

View File

@ -25,6 +25,7 @@ import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import java.util.HashMap; import java.util.HashMap;
@ -38,7 +39,7 @@ public class KeyCodeDescriptionMapper {
private static KeyCodeDescriptionMapper sInstance = new KeyCodeDescriptionMapper(); private static KeyCodeDescriptionMapper sInstance = new KeyCodeDescriptionMapper();
// Map of key labels to spoken description resource IDs // Map of key labels to spoken description resource IDs
private final HashMap<CharSequence, Integer> mKeyLabelMap; private final HashMap<CharSequence, Integer> mKeyLabelMap = CollectionUtils.newHashMap();
// Sparse array of spoken description resource IDs indexed by key codes // Sparse array of spoken description resource IDs indexed by key codes
private final SparseIntArray mKeyCodeMap; private final SparseIntArray mKeyCodeMap;
@ -52,7 +53,6 @@ public class KeyCodeDescriptionMapper {
} }
private KeyCodeDescriptionMapper() { private KeyCodeDescriptionMapper() {
mKeyLabelMap = new HashMap<CharSequence, Integer>();
mKeyCodeMap = new SparseIntArray(); mKeyCodeMap = new SparseIntArray();
} }

View File

@ -16,10 +16,6 @@
package com.android.inputmethod.compat; package com.android.inputmethod.compat;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.SuggestionSpanPickedNotificationReceiver;
import android.content.Context; import android.content.Context;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
@ -27,6 +23,11 @@ import android.text.Spanned;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.SuggestionSpanPickedNotificationReceiver;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
@ -119,7 +120,7 @@ public class SuggestionSpanUtils {
} else { } else {
spannable = new SpannableString(pickedWord); spannable = new SpannableString(pickedWord);
} }
final ArrayList<String> suggestionsList = new ArrayList<String>(); final ArrayList<String> suggestionsList = CollectionUtils.newArrayList();
for (int i = 0; i < suggestedWords.size(); ++i) { for (int i = 0; i < suggestedWords.size(); ++i) {
if (suggestionsList.size() >= OBJ_SUGGESTIONS_MAX_SIZE) { if (suggestionsList.size() >= OBJ_SUGGESTIONS_MAX_SIZE) {
break; break;

View File

@ -33,6 +33,7 @@ import com.android.inputmethod.keyboard.internal.KeyStyles;
import com.android.inputmethod.keyboard.internal.KeyboardCodesSet; import com.android.inputmethod.keyboard.internal.KeyboardCodesSet;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.keyboard.internal.KeyboardTextsSet; import com.android.inputmethod.keyboard.internal.KeyboardTextsSet;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.LocaleUtils.RunInLocale; import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
@ -254,9 +255,9 @@ public class Keyboard {
public int GRID_WIDTH; public int GRID_WIDTH;
public int GRID_HEIGHT; public int GRID_HEIGHT;
public final HashSet<Key> mKeys = new HashSet<Key>(); public final HashSet<Key> mKeys = CollectionUtils.newHashSet();
public final ArrayList<Key> mShiftKeys = new ArrayList<Key>(); public final ArrayList<Key> mShiftKeys = CollectionUtils.newArrayList();
public final ArrayList<Key> mAltCodeKeysWhileTyping = new ArrayList<Key>(); public final ArrayList<Key> mAltCodeKeysWhileTyping = CollectionUtils.newArrayList();
public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet(); public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet();
public final KeyboardCodesSet mCodesSet = new KeyboardCodesSet(); public final KeyboardCodesSet mCodesSet = new KeyboardCodesSet();
public final KeyboardTextsSet mTextsSet = new KeyboardTextsSet(); public final KeyboardTextsSet mTextsSet = new KeyboardTextsSet();

View File

@ -36,6 +36,7 @@ import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.compat.EditorInfoCompatUtils; import com.android.inputmethod.compat.EditorInfoCompatUtils;
import com.android.inputmethod.keyboard.KeyboardLayoutSet.Params.ElementParams; import com.android.inputmethod.keyboard.KeyboardLayoutSet.Params.ElementParams;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.InputAttributes; import com.android.inputmethod.latin.InputAttributes;
import com.android.inputmethod.latin.InputTypeUtils; import com.android.inputmethod.latin.InputTypeUtils;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
@ -71,7 +72,7 @@ public class KeyboardLayoutSet {
private final Params mParams; private final Params mParams;
private static final HashMap<KeyboardId, SoftReference<Keyboard>> sKeyboardCache = private static final HashMap<KeyboardId, SoftReference<Keyboard>> sKeyboardCache =
new HashMap<KeyboardId, SoftReference<Keyboard>>(); CollectionUtils.newHashMap();
private static final KeysCache sKeysCache = new KeysCache(); private static final KeysCache sKeysCache = new KeysCache();
public static class KeyboardLayoutSetException extends RuntimeException { public static class KeyboardLayoutSetException extends RuntimeException {
@ -84,11 +85,7 @@ public class KeyboardLayoutSet {
} }
public static class KeysCache { public static class KeysCache {
private final HashMap<Key, Key> mMap; private final HashMap<Key, Key> mMap = CollectionUtils.newHashMap();
public KeysCache() {
mMap = new HashMap<Key, Key>();
}
public void clear() { public void clear() {
mMap.clear(); mMap.clear();

View File

@ -39,6 +39,7 @@ import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import com.android.inputmethod.keyboard.internal.PreviewPlacerView; import com.android.inputmethod.keyboard.internal.PreviewPlacerView;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
@ -117,7 +118,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
/** True if all keys should be drawn */ /** True if all keys should be drawn */
private boolean mInvalidateAllKeys; private boolean mInvalidateAllKeys;
/** The keys that should be drawn */ /** The keys that should be drawn */
private final HashSet<Key> mInvalidatedKeys = new HashSet<Key>(); private final HashSet<Key> mInvalidatedKeys = CollectionUtils.newHashSet();
/** The working rectangle variable */ /** The working rectangle variable */
private final Rect mWorkingRect = new Rect(); private final Rect mWorkingRect = new Rect();
/** The keyboard bitmap buffer for faster updates */ /** The keyboard bitmap buffer for faster updates */

View File

@ -27,6 +27,7 @@ import android.widget.TextView;
import com.android.inputmethod.accessibility.AccessibilityUtils; import com.android.inputmethod.accessibility.AccessibilityUtils;
import com.android.inputmethod.keyboard.internal.GestureStroke; import com.android.inputmethod.keyboard.internal.GestureStroke;
import com.android.inputmethod.keyboard.internal.PointerTrackerQueue; import com.android.inputmethod.keyboard.internal.PointerTrackerQueue;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.InputPointers; import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.define.ProductionFlag;
@ -125,7 +126,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
private static int sTouchNoiseThresholdDistanceSquared; private static int sTouchNoiseThresholdDistanceSquared;
private static boolean sNeedsPhantomSuddenMoveEventHack; private static boolean sNeedsPhantomSuddenMoveEventHack;
private static final ArrayList<PointerTracker> sTrackers = new ArrayList<PointerTracker>(); private static final ArrayList<PointerTracker> sTrackers = CollectionUtils.newArrayList();
private static final InputPointers sAggregratedPointers = new InputPointers( private static final InputPointers sAggregratedPointers = new InputPointers(
GestureStroke.DEFAULT_CAPACITY); GestureStroke.DEFAULT_CAPACITY);
private static PointerTrackerQueue sPointerTrackerQueue; private static PointerTrackerQueue sPointerTrackerQueue;

View File

@ -21,6 +21,7 @@ import static com.android.inputmethod.keyboard.Keyboard.CODE_UNSPECIFIED;
import android.text.TextUtils; import android.text.TextUtils;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.StringUtils; import com.android.inputmethod.latin.StringUtils;
@ -258,7 +259,7 @@ public class KeySpecParser {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
final ArrayList<T> list = new ArrayList<T>(end - start); final ArrayList<T> list = CollectionUtils.newArrayList(end - start);
for (int i = start; i < end; i++) { for (int i = start; i < end; i++) {
list.add(array[i]); list.add(array[i]);
} }
@ -438,7 +439,7 @@ public class KeySpecParser {
// Skip empty entry. // Skip empty entry.
if (pos - start > 0) { if (pos - start > 0) {
if (list == null) { if (list == null) {
list = new ArrayList<String>(); list = CollectionUtils.newArrayList();
} }
list.add(text.substring(start, pos)); list.add(text.substring(start, pos));
} }

View File

@ -21,6 +21,7 @@ import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.XmlParseUtils; import com.android.inputmethod.latin.XmlParseUtils;
@ -33,7 +34,7 @@ public class KeyStyles {
private static final String TAG = KeyStyles.class.getSimpleName(); private static final String TAG = KeyStyles.class.getSimpleName();
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
final HashMap<String, KeyStyle> mStyles = new HashMap<String, KeyStyle>(); final HashMap<String, KeyStyle> mStyles = CollectionUtils.newHashMap();
final KeyboardTextsSet mTextsSet; final KeyboardTextsSet mTextsSet;
private final KeyStyle mEmptyKeyStyle; private final KeyStyle mEmptyKeyStyle;

View File

@ -17,13 +17,13 @@
package com.android.inputmethod.keyboard.internal; package com.android.inputmethod.keyboard.internal;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.latin.CollectionUtils;
import java.util.HashMap; import java.util.HashMap;
public class KeyboardCodesSet { public class KeyboardCodesSet {
private static final HashMap<String, int[]> sLanguageToCodesMap = private static final HashMap<String, int[]> sLanguageToCodesMap = CollectionUtils.newHashMap();
new HashMap<String, int[]>(); private static final HashMap<String, Integer> sNameToIdMap = CollectionUtils.newHashMap();
private static final HashMap<String, Integer> sNameToIdMap = new HashMap<String, Integer>();
private int[] mCodes = DEFAULT; private int[] mCodes = DEFAULT;

View File

@ -22,6 +22,7 @@ import android.graphics.drawable.Drawable;
import android.util.Log; import android.util.Log;
import android.util.SparseIntArray; import android.util.SparseIntArray;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import java.util.HashMap; import java.util.HashMap;
@ -35,7 +36,7 @@ public class KeyboardIconsSet {
private static final SparseIntArray ATTR_ID_TO_ICON_ID = new SparseIntArray(); private static final SparseIntArray ATTR_ID_TO_ICON_ID = new SparseIntArray();
// Icon name to icon id map. // Icon name to icon id map.
private static final HashMap<String, Integer> sNameToIdsMap = new HashMap<String, Integer>(); private static final HashMap<String, Integer> sNameToIdsMap = CollectionUtils.newHashMap();
private static final Object[] NAMES_AND_ATTR_IDS = { private static final Object[] NAMES_AND_ATTR_IDS = {
"undefined", ATTR_UNDEFINED, "undefined", ATTR_UNDEFINED,

View File

@ -19,6 +19,7 @@ package com.android.inputmethod.keyboard.internal;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import java.util.HashMap; import java.util.HashMap;
@ -45,14 +46,12 @@ import java.util.HashMap;
*/ */
public final class KeyboardTextsSet { public final class KeyboardTextsSet {
// Language to texts map. // Language to texts map.
private static final HashMap<String, String[]> sLocaleToTextsMap = private static final HashMap<String, String[]> sLocaleToTextsMap = CollectionUtils.newHashMap();
new HashMap<String, String[]>(); private static final HashMap<String, Integer> sNameToIdsMap = CollectionUtils.newHashMap();
private static final HashMap<String, Integer> sNameToIdsMap =
new HashMap<String, Integer>();
private String[] mTexts; private String[] mTexts;
// Resource name to text map. // Resource name to text map.
private HashMap<String, String> mResourceNameToTextsMap = new HashMap<String, String>(); private HashMap<String, String> mResourceNameToTextsMap = CollectionUtils.newHashMap();
public void setLanguage(final String language) { public void setLanguage(final String language) {
mTexts = sLocaleToTextsMap.get(language); mTexts = sLocaleToTextsMap.get(language);

View File

@ -18,6 +18,8 @@ package com.android.inputmethod.keyboard.internal;
import android.util.Log; import android.util.Log;
import com.android.inputmethod.latin.CollectionUtils;
import java.util.ArrayList; import java.util.ArrayList;
public class PointerTrackerQueue { public class PointerTrackerQueue {
@ -32,7 +34,7 @@ public class PointerTrackerQueue {
private static final int INITIAL_CAPACITY = 10; private static final int INITIAL_CAPACITY = 10;
private final ArrayList<Element> mExpandableArrayOfActivePointers = private final ArrayList<Element> mExpandableArrayOfActivePointers =
new ArrayList<Element>(INITIAL_CAPACITY); CollectionUtils.newArrayList(INITIAL_CAPACITY);
private int mArraySize = 0; private int mArraySize = 0;
public synchronized int size() { public synchronized int size() {

View File

@ -91,7 +91,7 @@ public class AdditionalSubtype {
} }
final String[] prefSubtypeArray = prefSubtypes.split(PREF_SUBTYPE_SEPARATOR); final String[] prefSubtypeArray = prefSubtypes.split(PREF_SUBTYPE_SEPARATOR);
final ArrayList<InputMethodSubtype> subtypesList = final ArrayList<InputMethodSubtype> subtypesList =
new ArrayList<InputMethodSubtype>(prefSubtypeArray.length); CollectionUtils.newArrayList(prefSubtypeArray.length);
for (final String prefSubtype : prefSubtypeArray) { for (final String prefSubtype : prefSubtypeArray) {
final InputMethodSubtype subtype = createAdditionalSubtype(prefSubtype); final InputMethodSubtype subtype = createAdditionalSubtype(prefSubtype);
if (subtype.getNameResId() == SubtypeLocale.UNKNOWN_KEYBOARD_LAYOUT) { if (subtype.getNameResId() == SubtypeLocale.UNKNOWN_KEYBOARD_LAYOUT) {

View File

@ -89,7 +89,7 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
super(context, android.R.layout.simple_spinner_item); super(context, android.R.layout.simple_spinner_item);
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
final TreeSet<SubtypeLocaleItem> items = new TreeSet<SubtypeLocaleItem>(); final TreeSet<SubtypeLocaleItem> items = CollectionUtils.newTreeSet();
final InputMethodInfo imi = ImfUtils.getInputMethodInfoOfThisIme(context); final InputMethodInfo imi = ImfUtils.getInputMethodInfoOfThisIme(context);
final int count = imi.getSubtypeCount(); final int count = imi.getSubtypeCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
@ -533,7 +533,7 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
private InputMethodSubtype[] getSubtypes() { private InputMethodSubtype[] getSubtypes() {
final PreferenceGroup group = getPreferenceScreen(); final PreferenceGroup group = getPreferenceScreen();
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); final ArrayList<InputMethodSubtype> subtypes = CollectionUtils.newArrayList();
final int count = group.getPreferenceCount(); final int count = group.getPreferenceCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
final Preference pref = group.getPreference(i); final Preference pref = group.getPreference(i);

View File

@ -160,7 +160,7 @@ public class BinaryDictionary extends Dictionary {
mUseFullEditDistance, mOutputChars, mOutputScores, mSpaceIndices, mOutputTypes); mUseFullEditDistance, mOutputChars, mOutputScores, mSpaceIndices, mOutputTypes);
final int count = Math.min(tmpCount, MAX_PREDICTIONS); final int count = Math.min(tmpCount, MAX_PREDICTIONS);
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>(); final ArrayList<SuggestedWordInfo> suggestions = CollectionUtils.newArrayList();
for (int j = 0; j < count; ++j) { for (int j = 0; j < count; ++j) {
if (composerSize > 0 && mOutputScores[j] < 1) break; if (composerSize > 0 && mOutputScores[j] < 1) break;
final int start = j * MAX_WORD_LENGTH; final int start = j * MAX_WORD_LENGTH;

View File

@ -99,7 +99,7 @@ public class BinaryDictionaryFileDumper {
} }
try { try {
final List<WordListInfo> list = new ArrayList<WordListInfo>(); final List<WordListInfo> list = CollectionUtils.newArrayList();
do { do {
final String wordListId = c.getString(0); final String wordListId = c.getString(0);
final String wordListLocale = c.getString(1); final String wordListLocale = c.getString(1);
@ -267,7 +267,7 @@ public class BinaryDictionaryFileDumper {
final ContentResolver resolver = context.getContentResolver(); final ContentResolver resolver = context.getContentResolver();
final List<WordListInfo> idList = getWordListWordListInfos(locale, context, final List<WordListInfo> idList = getWordListWordListInfos(locale, context,
hasDefaultWordList); hasDefaultWordList);
final List<AssetFileAddress> fileAddressList = new ArrayList<AssetFileAddress>(); final List<AssetFileAddress> fileAddressList = CollectionUtils.newArrayList();
for (WordListInfo id : idList) { for (WordListInfo id : idList) {
final AssetFileAddress afd = cacheWordList(id.mId, id.mLocale, resolver, context); final AssetFileAddress afd = cacheWordList(id.mId, id.mLocale, resolver, context);
if (null != afd) { if (null != afd) {

View File

@ -260,8 +260,7 @@ class BinaryDictionaryGetter {
final Context context) { final Context context) {
final File[] directoryList = getCachedDirectoryList(context); final File[] directoryList = getCachedDirectoryList(context);
if (null == directoryList) return EMPTY_FILE_ARRAY; if (null == directoryList) return EMPTY_FILE_ARRAY;
final HashMap<String, FileAndMatchLevel> cacheFiles = final HashMap<String, FileAndMatchLevel> cacheFiles = CollectionUtils.newHashMap();
new HashMap<String, FileAndMatchLevel>();
for (File directory : directoryList) { for (File directory : directoryList) {
if (!directory.isDirectory()) continue; if (!directory.isDirectory()) continue;
final String dirLocale = getWordListIdFromFileName(directory.getName()); final String dirLocale = getWordListIdFromFileName(directory.getName());
@ -359,7 +358,7 @@ class BinaryDictionaryGetter {
} }
final int formatVersion = raf.readInt(); final int formatVersion = raf.readInt();
final int headerSize = raf.readInt(); final int headerSize = raf.readInt();
final HashMap<String, String> options = new HashMap<String, String>(); final HashMap<String, String> options = CollectionUtils.newHashMap();
BinaryDictInputOutput.populateOptionsFromFile(raf, headerSize, options); BinaryDictInputOutput.populateOptionsFromFile(raf, headerSize, options);
final String version = options.get(VERSION_KEY); final String version = options.get(VERSION_KEY);
if (null == version) { if (null == version) {
@ -404,7 +403,7 @@ class BinaryDictionaryGetter {
final DictPackSettings dictPackSettings = new DictPackSettings(context); final DictPackSettings dictPackSettings = new DictPackSettings(context);
boolean foundMainDict = false; boolean foundMainDict = false;
final ArrayList<AssetFileAddress> fileList = new ArrayList<AssetFileAddress>(); final ArrayList<AssetFileAddress> fileList = CollectionUtils.newArrayList();
// cachedWordLists may not be null, see doc for getCachedDictionaryList // cachedWordLists may not be null, see doc for getCachedDictionaryList
for (final File f : cachedWordLists) { for (final File f : cachedWordLists) {
final String wordListId = getWordListIdFromFileName(f.getName()); final String wordListId = getWordListIdFromFileName(f.getName());

View File

@ -0,0 +1,89 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.inputmethod.latin;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
public class CollectionUtils {
private CollectionUtils() {
// This utility class is not publicly instantiable.
}
public static <K,V> HashMap<K,V> newHashMap() {
return new HashMap<K,V>();
}
public static <K,V> TreeMap<K,V> newTreeMap() {
return new TreeMap<K,V>();
}
public static <K, V> Map<K,V> newSynchronizedTreeMap() {
final TreeMap<K,V> treeMap = newTreeMap();
return Collections.synchronizedMap(treeMap);
}
public static <K,V> ConcurrentHashMap<K,V> newConcurrentHashMap() {
return new ConcurrentHashMap<K,V>();
}
public static <E> HashSet<E> newHashSet() {
return new HashSet<E>();
}
public static <E> TreeSet<E> newTreeSet() {
return new TreeSet<E>();
}
public static <E> ArrayList<E> newArrayList() {
return new ArrayList<E>();
}
public static <E> ArrayList<E> newArrayList(final int initialCapacity) {
return new ArrayList<E>(initialCapacity);
}
public static <E> ArrayList<E> newArrayList(final Collection<E> collection) {
return new ArrayList<E>(collection);
}
public static <E> LinkedList<E> newLinkedList() {
return new LinkedList<E>();
}
public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList() {
return new CopyOnWriteArrayList<E>();
}
public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList(
final Collection<E> collection) {
return new CopyOnWriteArrayList<E>(collection);
}
public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList(final E[] array) {
return new CopyOnWriteArrayList<E>(array);
}
}

View File

@ -35,22 +35,22 @@ public class DictionaryCollection extends Dictionary {
public DictionaryCollection(final String dictType) { public DictionaryCollection(final String dictType) {
super(dictType); super(dictType);
mDictionaries = new CopyOnWriteArrayList<Dictionary>(); mDictionaries = CollectionUtils.newCopyOnWriteArrayList();
} }
public DictionaryCollection(final String dictType, Dictionary... dictionaries) { public DictionaryCollection(final String dictType, Dictionary... dictionaries) {
super(dictType); super(dictType);
if (null == dictionaries) { if (null == dictionaries) {
mDictionaries = new CopyOnWriteArrayList<Dictionary>(); mDictionaries = CollectionUtils.newCopyOnWriteArrayList();
} else { } else {
mDictionaries = new CopyOnWriteArrayList<Dictionary>(dictionaries); mDictionaries = CollectionUtils.newCopyOnWriteArrayList(dictionaries);
mDictionaries.removeAll(Collections.singleton(null)); mDictionaries.removeAll(Collections.singleton(null));
} }
} }
public DictionaryCollection(final String dictType, Collection<Dictionary> dictionaries) { public DictionaryCollection(final String dictType, Collection<Dictionary> dictionaries) {
super(dictType); super(dictType);
mDictionaries = new CopyOnWriteArrayList<Dictionary>(dictionaries); mDictionaries = CollectionUtils.newCopyOnWriteArrayList(dictionaries);
mDictionaries.removeAll(Collections.singleton(null)); mDictionaries.removeAll(Collections.singleton(null));
} }
@ -63,7 +63,7 @@ public class DictionaryCollection extends Dictionary {
// dictionary and add the rest to it if not null, hence the get(0) // dictionary and add the rest to it if not null, hence the get(0)
ArrayList<SuggestedWordInfo> suggestions = dictionaries.get(0).getSuggestions(composer, ArrayList<SuggestedWordInfo> suggestions = dictionaries.get(0).getSuggestions(composer,
prevWord, proximityInfo); prevWord, proximityInfo);
if (null == suggestions) suggestions = new ArrayList<SuggestedWordInfo>(); if (null == suggestions) suggestions = CollectionUtils.newArrayList();
final int length = dictionaries.size(); final int length = dictionaries.size();
for (int i = 1; i < length; ++ i) { for (int i = 1; i < length; ++ i) {
final ArrayList<SuggestedWordInfo> sugg = dictionaries.get(i).getSuggestions(composer, final ArrayList<SuggestedWordInfo> sugg = dictionaries.get(i).getSuggestions(composer,

View File

@ -53,7 +53,7 @@ public class DictionaryFactory {
createBinaryDictionary(context, locale)); createBinaryDictionary(context, locale));
} }
final LinkedList<Dictionary> dictList = new LinkedList<Dictionary>(); final LinkedList<Dictionary> dictList = CollectionUtils.newLinkedList();
final ArrayList<AssetFileAddress> assetFileList = final ArrayList<AssetFileAddress> assetFileList =
BinaryDictionaryGetter.getDictionaryFiles(locale, context); BinaryDictionaryGetter.getDictionaryFiles(locale, context);
if (null != assetFileList) { if (null != assetFileList) {

View File

@ -62,7 +62,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
* that filename. * that filename.
*/ */
private static final HashMap<String, DictionaryController> sSharedDictionaryControllers = private static final HashMap<String, DictionaryController> sSharedDictionaryControllers =
new HashMap<String, DictionaryController>(); CollectionUtils.newHashMap();
/** The application context. */ /** The application context. */
protected final Context mContext; protected final Context mContext;
@ -159,9 +159,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
* the native side. * the native side.
*/ */
public void clearFusionDictionary() { public void clearFusionDictionary() {
final HashMap<String, String> attributes = CollectionUtils.newHashMap();
mFusionDictionary = new FusionDictionary(new Node(), mFusionDictionary = new FusionDictionary(new Node(),
new FusionDictionary.DictionaryOptions(new HashMap<String, String>(), false, new FusionDictionary.DictionaryOptions(attributes, false, false));
false));
} }
/** /**
@ -175,7 +175,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
mFusionDictionary.add(word, frequency, null); mFusionDictionary.add(word, frequency, null);
} else { } else {
// TODO: Do this in the subclass, with this class taking an arraylist. // TODO: Do this in the subclass, with this class taking an arraylist.
final ArrayList<WeightedString> shortcutTargets = new ArrayList<WeightedString>(); final ArrayList<WeightedString> shortcutTargets = CollectionUtils.newArrayList();
shortcutTargets.add(new WeightedString(shortcutTarget, frequency)); shortcutTargets.add(new WeightedString(shortcutTarget, frequency));
mFusionDictionary.add(word, frequency, shortcutTargets); mFusionDictionary.add(word, frequency, shortcutTargets);
} }

View File

@ -230,7 +230,7 @@ public class ExpandableDictionary extends Dictionary {
childNode.mTerminal = true; childNode.mTerminal = true;
if (isShortcutOnly) { if (isShortcutOnly) {
if (null == childNode.mShortcutTargets) { if (null == childNode.mShortcutTargets) {
childNode.mShortcutTargets = new ArrayList<char[]>(); childNode.mShortcutTargets = CollectionUtils.newArrayList();
} }
childNode.mShortcutTargets.add(shortcutTarget.toCharArray()); childNode.mShortcutTargets.add(shortcutTarget.toCharArray());
} else { } else {
@ -259,7 +259,7 @@ public class ExpandableDictionary extends Dictionary {
return suggestions; return suggestions;
} else { } else {
if (TextUtils.isEmpty(prevWord)) return null; if (TextUtils.isEmpty(prevWord)) return null;
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>(); final ArrayList<SuggestedWordInfo> suggestions = CollectionUtils.newArrayList();
runBigramReverseLookUp(prevWord, suggestions); runBigramReverseLookUp(prevWord, suggestions);
return suggestions; return suggestions;
} }
@ -278,7 +278,7 @@ public class ExpandableDictionary extends Dictionary {
protected ArrayList<SuggestedWordInfo> getWordsInner(final WordComposer codes, protected ArrayList<SuggestedWordInfo> getWordsInner(final WordComposer codes,
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) { final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>(); final ArrayList<SuggestedWordInfo> suggestions = CollectionUtils.newArrayList();
mInputLength = codes.size(); mInputLength = codes.size();
if (mCodes.length < mInputLength) mCodes = new int[mInputLength][]; if (mCodes.length < mInputLength) mCodes = new int[mInputLength][];
final InputPointers ips = codes.getInputPointers(); final InputPointers ips = codes.getInputPointers();
@ -550,7 +550,7 @@ public class ExpandableDictionary extends Dictionary {
Node secondWord = searchWord(mRoots, word2, 0, null); Node secondWord = searchWord(mRoots, word2, 0, null);
LinkedList<NextWord> bigrams = firstWord.mNGrams; LinkedList<NextWord> bigrams = firstWord.mNGrams;
if (bigrams == null || bigrams.size() == 0) { if (bigrams == null || bigrams.size() == 0) {
firstWord.mNGrams = new LinkedList<NextWord>(); firstWord.mNGrams = CollectionUtils.newLinkedList();
bigrams = firstWord.mNGrams; bigrams = firstWord.mNGrams;
} else { } else {
for (NextWord nw : bigrams) { for (NextWord nw : bigrams) {

View File

@ -193,7 +193,7 @@ public class LocaleUtils {
} }
} }
private static final HashMap<String, Locale> sLocaleCache = new HashMap<String, Locale>(); private static final HashMap<String, Locale> sLocaleCache = CollectionUtils.newHashMap();
/** /**
* Creates a locale from a string specification. * Creates a locale from a string specification.

View File

@ -185,7 +185,7 @@ public class SettingsValues {
// Helper functions to create member values. // Helper functions to create member values.
private static SuggestedWords createSuggestPuncList(final String[] puncs) { private static SuggestedWords createSuggestPuncList(final String[] puncs) {
final ArrayList<SuggestedWordInfo> puncList = new ArrayList<SuggestedWordInfo>(); final ArrayList<SuggestedWordInfo> puncList = CollectionUtils.newArrayList();
if (puncs != null) { if (puncs != null) {
for (final String puncSpec : puncs) { for (final String puncSpec : puncs) {
puncList.add(new SuggestedWordInfo(KeySpecParser.getLabel(puncSpec), puncList.add(new SuggestedWordInfo(KeySpecParser.getLabel(puncSpec),

View File

@ -53,7 +53,7 @@ public class StringUtils {
if (TextUtils.isEmpty(csv)) return ""; if (TextUtils.isEmpty(csv)) return "";
final String[] elements = csv.split(","); final String[] elements = csv.split(",");
if (!containsInArray(key, elements)) return csv; if (!containsInArray(key, elements)) return csv;
final ArrayList<String> result = new ArrayList<String>(elements.length - 1); final ArrayList<String> result = CollectionUtils.newArrayList(elements.length - 1);
for (final String element : elements) { for (final String element : elements) {
if (!key.equals(element)) result.add(element); if (!key.equals(element)) result.add(element);
} }

View File

@ -45,13 +45,13 @@ public class SubtypeLocale {
private static String[] sPredefinedKeyboardLayoutSet; private static String[] sPredefinedKeyboardLayoutSet;
// Keyboard layout to its display name map. // Keyboard layout to its display name map.
private static final HashMap<String, String> sKeyboardLayoutToDisplayNameMap = private static final HashMap<String, String> sKeyboardLayoutToDisplayNameMap =
new HashMap<String, String>(); CollectionUtils.newHashMap();
// Keyboard layout to subtype name resource id map. // Keyboard layout to subtype name resource id map.
private static final HashMap<String, Integer> sKeyboardLayoutToNameIdsMap = private static final HashMap<String, Integer> sKeyboardLayoutToNameIdsMap =
new HashMap<String, Integer>(); CollectionUtils.newHashMap();
// Exceptional locale to subtype name resource id map. // Exceptional locale to subtype name resource id map.
private static final HashMap<String, Integer> sExceptionalLocaleToWithLayoutNameIdsMap = private static final HashMap<String, Integer> sExceptionalLocaleToWithLayoutNameIdsMap =
new HashMap<String, Integer>(); CollectionUtils.newHashMap();
private static final String SUBTYPE_NAME_RESOURCE_GENERIC_PREFIX = private static final String SUBTYPE_NAME_RESOURCE_GENERIC_PREFIX =
"string/subtype_generic_"; "string/subtype_generic_";
private static final String SUBTYPE_NAME_RESOURCE_WITH_LAYOUT_PREFIX = private static final String SUBTYPE_NAME_RESOURCE_WITH_LAYOUT_PREFIX =
@ -60,11 +60,11 @@ public class SubtypeLocale {
"string/subtype_no_language_"; "string/subtype_no_language_";
// Exceptional locales to display name map. // Exceptional locales to display name map.
private static final HashMap<String, String> sExceptionalDisplayNamesMap = private static final HashMap<String, String> sExceptionalDisplayNamesMap =
new HashMap<String, String>(); CollectionUtils.newHashMap();
// Keyboard layout set name for the subtypes that don't have a keyboardLayoutSet extra value. // Keyboard layout set name for the subtypes that don't have a keyboardLayoutSet extra value.
// This is for compatibility to keep the same subtype ids as pre-JellyBean. // This is for compatibility to keep the same subtype ids as pre-JellyBean.
private static final HashMap<String,String> sLocaleAndExtraValueToKeyboardLayoutSetMap = private static final HashMap<String,String> sLocaleAndExtraValueToKeyboardLayoutSetMap =
new HashMap<String,String>(); CollectionUtils.newHashMap();
private SubtypeLocale() { private SubtypeLocale() {
// Intentional empty constructor for utility class. // Intentional empty constructor for utility class.

View File

@ -51,7 +51,7 @@ public class Suggest {
private Dictionary mMainDictionary; private Dictionary mMainDictionary;
private ContactsBinaryDictionary mContactsDict; private ContactsBinaryDictionary mContactsDict;
private final ConcurrentHashMap<String, Dictionary> mDictionaries = private final ConcurrentHashMap<String, Dictionary> mDictionaries =
new ConcurrentHashMap<String, Dictionary>(); CollectionUtils.newConcurrentHashMap();
public static final int MAX_SUGGESTIONS = 18; public static final int MAX_SUGGESTIONS = 18;
@ -242,7 +242,7 @@ public class Suggest {
} }
final ArrayList<SuggestedWordInfo> suggestionsContainer = final ArrayList<SuggestedWordInfo> suggestionsContainer =
new ArrayList<SuggestedWordInfo>(suggestionsSet); CollectionUtils.newArrayList(suggestionsSet);
final int suggestionsCount = suggestionsContainer.size(); final int suggestionsCount = suggestionsContainer.size();
final boolean isFirstCharCapitalized = wordComposer.isFirstCharCapitalized(); final boolean isFirstCharCapitalized = wordComposer.isFirstCharCapitalized();
final boolean isAllUpperCase = wordComposer.isAllUpperCase(); final boolean isAllUpperCase = wordComposer.isAllUpperCase();
@ -307,7 +307,7 @@ public class Suggest {
} }
final ArrayList<SuggestedWordInfo> suggestionsContainer = final ArrayList<SuggestedWordInfo> suggestionsContainer =
new ArrayList<SuggestedWordInfo>(suggestionsSet); CollectionUtils.newArrayList(suggestionsSet);
final int suggestionsCount = suggestionsContainer.size(); final int suggestionsCount = suggestionsContainer.size();
final boolean isFirstCharCapitalized = wordComposer.wasShiftedNoLock(); final boolean isFirstCharCapitalized = wordComposer.wasShiftedNoLock();
final boolean isAllUpperCase = wordComposer.isAllUpperCase(); final boolean isAllUpperCase = wordComposer.isAllUpperCase();
@ -338,7 +338,7 @@ public class Suggest {
typedWordInfo.setDebugString("+"); typedWordInfo.setDebugString("+");
final int suggestionsSize = suggestions.size(); final int suggestionsSize = suggestions.size();
final ArrayList<SuggestedWordInfo> suggestionsList = final ArrayList<SuggestedWordInfo> suggestionsList =
new ArrayList<SuggestedWordInfo>(suggestionsSize); CollectionUtils.newArrayList(suggestionsSize);
suggestionsList.add(typedWordInfo); suggestionsList.add(typedWordInfo);
// Note: i here is the index in mScores[], but the index in mSuggestions is one more // Note: i here is the index in mScores[], but the index in mSuggestions is one more
// than i because we added the typed word to mSuggestions without touching mScores. // than i because we added the typed word to mSuggestions without touching mScores.
@ -391,7 +391,7 @@ public class Suggest {
} }
public void close() { public void close() {
final HashSet<Dictionary> dictionaries = new HashSet<Dictionary>(); final HashSet<Dictionary> dictionaries = CollectionUtils.newHashSet();
dictionaries.addAll(mDictionaries.values()); dictionaries.addAll(mDictionaries.values());
for (final Dictionary dictionary : dictionaries) { for (final Dictionary dictionary : dictionaries) {
dictionary.close(); dictionary.close();

View File

@ -24,8 +24,10 @@ import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
public class SuggestedWords { public class SuggestedWords {
private static final ArrayList<SuggestedWordInfo> EMPTY_WORD_INFO_LIST =
CollectionUtils.newArrayList(0);
public static final SuggestedWords EMPTY = new SuggestedWords( public static final SuggestedWords EMPTY = new SuggestedWords(
new ArrayList<SuggestedWordInfo>(0), false, false, false, false, false); EMPTY_WORD_INFO_LIST, false, false, false, false, false);
public final boolean mTypedWordValid; public final boolean mTypedWordValid;
// Note: this INCLUDES cases where the word will auto-correct to itself. A good definition // Note: this INCLUDES cases where the word will auto-correct to itself. A good definition
@ -83,7 +85,7 @@ public class SuggestedWords {
public static ArrayList<SuggestedWordInfo> getFromApplicationSpecifiedCompletions( public static ArrayList<SuggestedWordInfo> getFromApplicationSpecifiedCompletions(
final CompletionInfo[] infos) { final CompletionInfo[] infos) {
final ArrayList<SuggestedWordInfo> result = new ArrayList<SuggestedWordInfo>(); final ArrayList<SuggestedWordInfo> result = CollectionUtils.newArrayList();
for (CompletionInfo info : infos) { for (CompletionInfo info : infos) {
if (null != info && info.getText() != null) { if (null != info && info.getText() != null) {
result.add(new SuggestedWordInfo(info.getText(), SuggestedWordInfo.MAX_SCORE, result.add(new SuggestedWordInfo(info.getText(), SuggestedWordInfo.MAX_SCORE,
@ -97,8 +99,8 @@ public class SuggestedWords {
// and replace it with what the user currently typed. // and replace it with what the user currently typed.
public static ArrayList<SuggestedWordInfo> getTypedWordAndPreviousSuggestions( public static ArrayList<SuggestedWordInfo> getTypedWordAndPreviousSuggestions(
final CharSequence typedWord, final SuggestedWords previousSuggestions) { final CharSequence typedWord, final SuggestedWords previousSuggestions) {
final ArrayList<SuggestedWordInfo> suggestionsList = new ArrayList<SuggestedWordInfo>(); final ArrayList<SuggestedWordInfo> suggestionsList = CollectionUtils.newArrayList();
final HashSet<String> alreadySeen = new HashSet<String>(); final HashSet<String> alreadySeen = CollectionUtils.newHashSet();
suggestionsList.add(new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE, suggestionsList.add(new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE,
SuggestedWordInfo.KIND_TYPED, Dictionary.TYPE_USER_TYPED)); SuggestedWordInfo.KIND_TYPED, Dictionary.TYPE_USER_TYPED));
alreadySeen.add(typedWord.toString()); alreadySeen.add(typedWord.toString());

View File

@ -93,10 +93,10 @@ public class UserHistoryDictionary extends ExpandableDictionary {
private final static HashMap<String, String> sDictProjectionMap; private final static HashMap<String, String> sDictProjectionMap;
private final static ConcurrentHashMap<String, SoftReference<UserHistoryDictionary>> private final static ConcurrentHashMap<String, SoftReference<UserHistoryDictionary>>
sLangDictCache = new ConcurrentHashMap<String, SoftReference<UserHistoryDictionary>>(); sLangDictCache = CollectionUtils.newConcurrentHashMap();
static { static {
sDictProjectionMap = new HashMap<String, String>(); sDictProjectionMap = CollectionUtils.newHashMap();
sDictProjectionMap.put(MAIN_COLUMN_ID, MAIN_COLUMN_ID); sDictProjectionMap.put(MAIN_COLUMN_ID, MAIN_COLUMN_ID);
sDictProjectionMap.put(MAIN_COLUMN_WORD1, MAIN_COLUMN_WORD1); sDictProjectionMap.put(MAIN_COLUMN_WORD1, MAIN_COLUMN_WORD1);
sDictProjectionMap.put(MAIN_COLUMN_WORD2, MAIN_COLUMN_WORD2); sDictProjectionMap.put(MAIN_COLUMN_WORD2, MAIN_COLUMN_WORD2);

View File

@ -29,9 +29,8 @@ import java.util.Set;
public class UserHistoryDictionaryBigramList { public class UserHistoryDictionaryBigramList {
public static final byte FORGETTING_CURVE_INITIAL_VALUE = 0; public static final byte FORGETTING_CURVE_INITIAL_VALUE = 0;
private static final String TAG = UserHistoryDictionaryBigramList.class.getSimpleName(); private static final String TAG = UserHistoryDictionaryBigramList.class.getSimpleName();
private static final HashMap<String, Byte> EMPTY_BIGRAM_MAP = new HashMap<String, Byte>(); private static final HashMap<String, Byte> EMPTY_BIGRAM_MAP = CollectionUtils.newHashMap();
private final HashMap<String, HashMap<String, Byte>> mBigramMap = private final HashMap<String, HashMap<String, Byte>> mBigramMap = CollectionUtils.newHashMap();
new HashMap<String, HashMap<String, Byte>>();
private int mSize = 0; private int mSize = 0;
public void evictAll() { public void evictAll() {
@ -57,7 +56,7 @@ public class UserHistoryDictionaryBigramList {
if (mBigramMap.containsKey(word1)) { if (mBigramMap.containsKey(word1)) {
map = mBigramMap.get(word1); map = mBigramMap.get(word1);
} else { } else {
map = new HashMap<String, Byte>(); map = CollectionUtils.newHashMap();
mBigramMap.put(word1, map); mBigramMap.put(word1, map);
} }
if (!map.containsKey(word2)) { if (!map.containsKey(word2)) {

View File

@ -477,7 +477,7 @@ public class Utils {
private static final String HARDWARE_PREFIX = Build.HARDWARE + ","; private static final String HARDWARE_PREFIX = Build.HARDWARE + ",";
private static final HashMap<String, String> sDeviceOverrideValueMap = private static final HashMap<String, String> sDeviceOverrideValueMap =
new HashMap<String, String>(); CollectionUtils.newHashMap();
public static String getDeviceOverrideValue(Resources res, int overrideResId, String defValue) { public static String getDeviceOverrideValue(Resources res, int overrideResId, String defValue) {
final int orientation = res.getConfiguration().orientation; final int orientation = res.getConfiguration().orientation;
@ -495,7 +495,7 @@ public class Utils {
return sDeviceOverrideValueMap.get(key); return sDeviceOverrideValueMap.get(key);
} }
private static final HashMap<String, Long> EMPTY_LT_HASH_MAP = new HashMap<String, Long>(); private static final HashMap<String, Long> EMPTY_LT_HASH_MAP = CollectionUtils.newHashMap();
private static final String LOCALE_AND_TIME_STR_SEPARATER = ","; private static final String LOCALE_AND_TIME_STR_SEPARATER = ",";
public static HashMap<String, Long> localeAndTimeStrToHashMap(String str) { public static HashMap<String, Long> localeAndTimeStrToHashMap(String str) {
if (TextUtils.isEmpty(str)) { if (TextUtils.isEmpty(str)) {
@ -506,7 +506,7 @@ public class Utils {
if (N < 2 || N % 2 != 0) { if (N < 2 || N % 2 != 0) {
return EMPTY_LT_HASH_MAP; return EMPTY_LT_HASH_MAP;
} }
final HashMap<String, Long> retval = new HashMap<String, Long>(); final HashMap<String, Long> retval = CollectionUtils.newHashMap();
for (int i = 0; i < N / 2; ++i) { for (int i = 0; i < N / 2; ++i) {
final String localeStr = ss[i * 2]; final String localeStr = ss[i * 2];
final long time = Long.valueOf(ss[i * 2 + 1]); final long time = Long.valueOf(ss[i * 2 + 1]);

View File

@ -25,6 +25,7 @@ import android.view.textservice.SuggestionsInfo;
import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.BinaryDictionary; import com.android.inputmethod.latin.BinaryDictionary;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.ContactsBinaryDictionary; import com.android.inputmethod.latin.ContactsBinaryDictionary;
import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.DictionaryCollection; import com.android.inputmethod.latin.DictionaryCollection;
@ -62,10 +63,9 @@ public class AndroidSpellCheckerService extends SpellCheckerService
public static final int CAPITALIZE_ALL = 2; // All caps public static final int CAPITALIZE_ALL = 2; // All caps
private final static String[] EMPTY_STRING_ARRAY = new String[0]; private final static String[] EMPTY_STRING_ARRAY = new String[0];
private Map<String, DictionaryPool> mDictionaryPools = private Map<String, DictionaryPool> mDictionaryPools = CollectionUtils.newSynchronizedTreeMap();
Collections.synchronizedMap(new TreeMap<String, DictionaryPool>());
private Map<String, UserBinaryDictionary> mUserDictionaries = private Map<String, UserBinaryDictionary> mUserDictionaries =
Collections.synchronizedMap(new TreeMap<String, UserBinaryDictionary>()); CollectionUtils.newSynchronizedTreeMap();
private ContactsBinaryDictionary mContactsDictionary; private ContactsBinaryDictionary mContactsDictionary;
// The threshold for a candidate to be offered as a suggestion. // The threshold for a candidate to be offered as a suggestion.
@ -77,7 +77,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
private final Object mUseContactsLock = new Object(); private final Object mUseContactsLock = new Object();
private final HashSet<WeakReference<DictionaryCollection>> mDictionaryCollectionsList = private final HashSet<WeakReference<DictionaryCollection>> mDictionaryCollectionsList =
new HashSet<WeakReference<DictionaryCollection>>(); CollectionUtils.newHashSet();
public static final int SCRIPT_LATIN = 0; public static final int SCRIPT_LATIN = 0;
public static final int SCRIPT_CYRILLIC = 1; public static final int SCRIPT_CYRILLIC = 1;
@ -93,7 +93,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
// proximity to pass to the dictionary descent algorithm. // proximity to pass to the dictionary descent algorithm.
// IMPORTANT: this only contains languages - do not write countries in there. // IMPORTANT: this only contains languages - do not write countries in there.
// Only the language is searched from the map. // Only the language is searched from the map.
mLanguageToScript = new TreeMap<String, Integer>(); mLanguageToScript = CollectionUtils.newTreeMap();
mLanguageToScript.put("en", SCRIPT_LATIN); mLanguageToScript.put("en", SCRIPT_LATIN);
mLanguageToScript.put("fr", SCRIPT_LATIN); mLanguageToScript.put("fr", SCRIPT_LATIN);
mLanguageToScript.put("de", SCRIPT_LATIN); mLanguageToScript.put("de", SCRIPT_LATIN);
@ -231,7 +231,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
mSuggestionThreshold = suggestionThreshold; mSuggestionThreshold = suggestionThreshold;
mRecommendedThreshold = recommendedThreshold; mRecommendedThreshold = recommendedThreshold;
mMaxLength = maxLength; mMaxLength = maxLength;
mSuggestions = new ArrayList<CharSequence>(maxLength + 1); mSuggestions = CollectionUtils.newArrayList(maxLength + 1);
mScores = new int[mMaxLength]; mScores = new int[mMaxLength];
} }
@ -359,10 +359,9 @@ public class AndroidSpellCheckerService extends SpellCheckerService
private void closeAllDictionaries() { private void closeAllDictionaries() {
final Map<String, DictionaryPool> oldPools = mDictionaryPools; final Map<String, DictionaryPool> oldPools = mDictionaryPools;
mDictionaryPools = Collections.synchronizedMap(new TreeMap<String, DictionaryPool>()); mDictionaryPools = CollectionUtils.newSynchronizedTreeMap();
final Map<String, UserBinaryDictionary> oldUserDictionaries = mUserDictionaries; final Map<String, UserBinaryDictionary> oldUserDictionaries = mUserDictionaries;
mUserDictionaries = mUserDictionaries = CollectionUtils.newSynchronizedTreeMap();
Collections.synchronizedMap(new TreeMap<String, UserBinaryDictionary>());
new Thread("spellchecker_close_dicts") { new Thread("spellchecker_close_dicts") {
@Override @Override
public void run() { public void run() {

View File

@ -22,6 +22,8 @@ import android.view.textservice.SentenceSuggestionsInfo;
import android.view.textservice.SuggestionsInfo; import android.view.textservice.SuggestionsInfo;
import android.view.textservice.TextInfo; import android.view.textservice.TextInfo;
import com.android.inputmethod.latin.CollectionUtils;
import java.util.ArrayList; import java.util.ArrayList;
public class AndroidSpellCheckerSession extends AndroidWordLevelSpellCheckerSession { public class AndroidSpellCheckerSession extends AndroidWordLevelSpellCheckerSession {
@ -40,10 +42,10 @@ public class AndroidSpellCheckerSession extends AndroidWordLevelSpellCheckerSess
return null; return null;
} }
final int N = ssi.getSuggestionsCount(); final int N = ssi.getSuggestionsCount();
final ArrayList<Integer> additionalOffsets = new ArrayList<Integer>(); final ArrayList<Integer> additionalOffsets = CollectionUtils.newArrayList();
final ArrayList<Integer> additionalLengths = new ArrayList<Integer>(); final ArrayList<Integer> additionalLengths = CollectionUtils.newArrayList();
final ArrayList<SuggestionsInfo> additionalSuggestionsInfos = final ArrayList<SuggestionsInfo> additionalSuggestionsInfos =
new ArrayList<SuggestionsInfo>(); CollectionUtils.newArrayList();
String currentWord = null; String currentWord = null;
for (int i = 0; i < N; ++i) { for (int i = 0; i < N; ++i) {
final SuggestionsInfo si = ssi.getSuggestionsInfoAt(i); final SuggestionsInfo si = ssi.getSuggestionsInfoAt(i);

View File

@ -19,6 +19,7 @@ package com.android.inputmethod.latin.spellcheck;
import android.util.Log; import android.util.Log;
import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.WordComposer; import com.android.inputmethod.latin.WordComposer;
@ -45,7 +46,7 @@ public class DictionaryPool extends LinkedBlockingQueue<DictAndProximity> {
private final Locale mLocale; private final Locale mLocale;
private int mSize; private int mSize;
private volatile boolean mClosed; private volatile boolean mClosed;
final static ArrayList<SuggestedWordInfo> noSuggestions = new ArrayList<SuggestedWordInfo>(); final static ArrayList<SuggestedWordInfo> noSuggestions = CollectionUtils.newArrayList();
private final static DictAndProximity dummyDict = new DictAndProximity( private final static DictAndProximity dummyDict = new DictAndProximity(
new Dictionary(Dictionary.TYPE_MAIN) { new Dictionary(Dictionary.TYPE_MAIN) {
@Override @Override

View File

@ -17,6 +17,7 @@
package com.android.inputmethod.latin.spellcheck; package com.android.inputmethod.latin.spellcheck;
import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import java.util.TreeMap; import java.util.TreeMap;
@ -59,7 +60,7 @@ public class SpellCheckerProximityInfo {
// character. // character.
// Since we need to build such an array, we want to be able to search in our big proximity // Since we need to build such an array, we want to be able to search in our big proximity
// data quickly by character, and a map is probably the best way to do this. // data quickly by character, and a map is probably the best way to do this.
final private static TreeMap<Integer, Integer> INDICES = new TreeMap<Integer, Integer>(); final private static TreeMap<Integer, Integer> INDICES = CollectionUtils.newTreeMap();
// The proximity here is the union of // The proximity here is the union of
// - the proximity for a QWERTY keyboard. // - the proximity for a QWERTY keyboard.
@ -122,7 +123,7 @@ public class SpellCheckerProximityInfo {
} }
private static class Cyrillic { private static class Cyrillic {
final private static TreeMap<Integer, Integer> INDICES = new TreeMap<Integer, Integer>(); final private static TreeMap<Integer, Integer> INDICES = CollectionUtils.newTreeMap();
// TODO: The following table is solely based on the keyboard layout. Consult with Russian // TODO: The following table is solely based on the keyboard layout. Consult with Russian
// speakers on commonly misspelled words/letters. // speakers on commonly misspelled words/letters.
final static int[] PROXIMITY = { final static int[] PROXIMITY = {

View File

@ -58,6 +58,7 @@ import com.android.inputmethod.keyboard.MoreKeysPanel;
import com.android.inputmethod.keyboard.PointerTracker; import com.android.inputmethod.keyboard.PointerTracker;
import com.android.inputmethod.keyboard.ViewLayoutUtils; import com.android.inputmethod.keyboard.ViewLayoutUtils;
import com.android.inputmethod.latin.AutoCorrection; import com.android.inputmethod.latin.AutoCorrection;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.StaticInnerHandlerWrapper; import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
@ -88,9 +89,9 @@ public class SuggestionStripView extends RelativeLayout implements OnClickListen
private final MoreSuggestions.Builder mMoreSuggestionsBuilder; private final MoreSuggestions.Builder mMoreSuggestionsBuilder;
private final PopupWindow mMoreSuggestionsWindow; private final PopupWindow mMoreSuggestionsWindow;
private final ArrayList<TextView> mWords = new ArrayList<TextView>(); private final ArrayList<TextView> mWords = CollectionUtils.newArrayList();
private final ArrayList<TextView> mInfos = new ArrayList<TextView>(); private final ArrayList<TextView> mInfos = CollectionUtils.newArrayList();
private final ArrayList<View> mDividers = new ArrayList<View>(); private final ArrayList<View> mDividers = CollectionUtils.newArrayList();
private final PopupWindow mPreviewPopup; private final PopupWindow mPreviewPopup;
private final TextView mPreviewText; private final TextView mPreviewText;
@ -167,7 +168,7 @@ public class SuggestionStripView extends RelativeLayout implements OnClickListen
private final int mSuggestionStripOption; private final int mSuggestionStripOption;
private final ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(); private final ArrayList<CharSequence> mTexts = CollectionUtils.newArrayList();
public boolean mMoreSuggestionsAvailable; public boolean mMoreSuggestionsAvailable;

View File

@ -57,6 +57,7 @@ import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.keyboard.MainKeyboardView; import com.android.inputmethod.keyboard.MainKeyboardView;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinIME;
@ -115,7 +116,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
// the system to do so. // the system to do so.
/* package */ ResearchLog mIntentionalResearchLog; /* package */ ResearchLog mIntentionalResearchLog;
// LogUnits are queued here and released only when the user requests the intentional log. // LogUnits are queued here and released only when the user requests the intentional log.
private List<LogUnit> mIntentionalResearchLogQueue = new ArrayList<LogUnit>(); private List<LogUnit> mIntentionalResearchLogQueue = CollectionUtils.newArrayList();
private boolean mIsPasswordView = false; private boolean mIsPasswordView = false;
private boolean mIsLoggingSuspended = false; private boolean mIsLoggingSuspended = false;
@ -514,7 +515,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
private void saveLogsForFeedback() { private void saveLogsForFeedback() {
mFeedbackLog = mIntentionalResearchLog; mFeedbackLog = mIntentionalResearchLog;
if (mIntentionalResearchLogQueue != null) { if (mIntentionalResearchLogQueue != null) {
mFeedbackQueue = new ArrayList<LogUnit>(mIntentionalResearchLogQueue); mFeedbackQueue = CollectionUtils.newArrayList(mIntentionalResearchLogQueue);
} else { } else {
mFeedbackQueue = null; mFeedbackQueue = null;
} }
@ -524,7 +525,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
mMainResearchLog = null; mMainResearchLog = null;
mIntentionalResearchLog = null; mIntentionalResearchLog = null;
mIntentionalResearchLogQueue = new ArrayList<LogUnit>(); mIntentionalResearchLogQueue = CollectionUtils.newArrayList();
} }
private static final int LOG_DRAIN_TIMEOUT_IN_MS = 1000 * 5; private static final int LOG_DRAIN_TIMEOUT_IN_MS = 1000 * 5;
@ -781,9 +782,9 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
} }
static class LogUnit { static class LogUnit {
private final List<String[]> mKeysList = new ArrayList<String[]>(); private final List<String[]> mKeysList = CollectionUtils.newArrayList();
private final List<Object[]> mValuesList = new ArrayList<Object[]>(); private final List<Object[]> mValuesList = CollectionUtils.newArrayList();
private final List<Boolean> mIsPotentiallyPrivate = new ArrayList<Boolean>(); private final List<Boolean> mIsPotentiallyPrivate = CollectionUtils.newArrayList();
private void addLogAtom(final String[] keys, final Object[] values, private void addLogAtom(final String[] keys, final Object[] values,
final Boolean isPotentiallyPrivate) { final Boolean isPotentiallyPrivate) {

View File

@ -22,6 +22,7 @@ import android.test.AndroidTestCase;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.latin.AdditionalSubtype; import com.android.inputmethod.latin.AdditionalSubtype;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.ImfUtils; import com.android.inputmethod.latin.ImfUtils;
import com.android.inputmethod.latin.StringUtils; import com.android.inputmethod.latin.StringUtils;
import com.android.inputmethod.latin.SubtypeLocale; import com.android.inputmethod.latin.SubtypeLocale;
@ -31,7 +32,7 @@ import java.util.Locale;
public class SpacebarTextTests extends AndroidTestCase { public class SpacebarTextTests extends AndroidTestCase {
// Locale to subtypes list. // Locale to subtypes list.
private final ArrayList<InputMethodSubtype> mSubtypesList = new ArrayList<InputMethodSubtype>(); private final ArrayList<InputMethodSubtype> mSubtypesList = CollectionUtils.newArrayList();
private Resources mRes; private Resources mRes;

View File

@ -19,6 +19,8 @@ package com.android.inputmethod.keyboard.internal;
import android.app.Instrumentation; import android.app.Instrumentation;
import android.test.InstrumentationTestCase; import android.test.InstrumentationTestCase;
import com.android.inputmethod.latin.CollectionUtils;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -42,7 +44,7 @@ public class KeySpecParserCsvTests extends InstrumentationTestCase {
} }
private static String[] getAllResourceIdNames(final Class<?> resourceIdClass) { private static String[] getAllResourceIdNames(final Class<?> resourceIdClass) {
final ArrayList<String> names = new ArrayList<String>(); final ArrayList<String> names = CollectionUtils.newArrayList();
for (final Field field : resourceIdClass.getFields()) { for (final Field field : resourceIdClass.getFields()) {
if (field.getType() == Integer.TYPE) { if (field.getType() == Integer.TYPE) {
names.add(field.getName()); names.add(field.getName());

View File

@ -28,7 +28,7 @@ import java.util.Locale;
public class SubtypeLocaleTests extends AndroidTestCase { public class SubtypeLocaleTests extends AndroidTestCase {
// Locale to subtypes list. // Locale to subtypes list.
private final ArrayList<InputMethodSubtype> mSubtypesList = new ArrayList<InputMethodSubtype>(); private final ArrayList<InputMethodSubtype> mSubtypesList = CollectionUtils.newArrayList();
private Resources mRes; private Resources mRes;

View File

@ -19,6 +19,7 @@ package com.android.inputmethod.keyboard.internal;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import java.util.HashMap; import java.util.HashMap;
@ -45,14 +46,12 @@ import java.util.HashMap;
*/ */
public final class KeyboardTextsSet { public final class KeyboardTextsSet {
// Language to texts map. // Language to texts map.
private static final HashMap<String, String[]> sLocaleToTextsMap = private static final HashMap<String, String[]> sLocaleToTextsMap = CollectionUtils.newHashMap();
new HashMap<String, String[]>(); private static final HashMap<String, Integer> sNameToIdsMap = CollectionUtils.newHashMap();
private static final HashMap<String, Integer> sNameToIdsMap =
new HashMap<String, Integer>();
private String[] mTexts; private String[] mTexts;
// Resource name to text map. // Resource name to text map.
private HashMap<String, String> mResourceNameToTextsMap = new HashMap<String, String>(); private HashMap<String, String> mResourceNameToTextsMap = CollectionUtils.newHashMap();
public void setLanguage(final String language) { public void setLanguage(final String language) {
mTexts = sLocaleToTextsMap.get(language); mTexts = sLocaleToTextsMap.get(language);