From a91561aa58db1c43092c1caecc051a11fa5391c7 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 23 May 2014 20:18:17 +0900 Subject: [PATCH] Use Java 7 diamond operator Change-Id: If16ef50ae73147594615d0f49d6a22621eaf1aef --- java/proguard.flags | 5 +- .../MainKeyboardAccessibilityDelegate.java | 5 - .../compat/SuggestionSpanUtils.java | 3 +- .../dictionarypack/ActionBatch.java | 3 +- .../DictionaryDownloadProgressBar.java | 2 - .../DictionaryListInterfaceState.java | 6 +- .../dictionarypack/DictionaryProvider.java | 2 +- .../DictionarySettingsFragment.java | 13 +- .../dictionarypack/LocaleUtils.java | 2 +- .../dictionarypack/MetadataDbHelper.java | 6 +- .../dictionarypack/MetadataHandler.java | 2 +- .../dictionarypack/MetadataParser.java | 4 +- .../dictionarypack/UpdateHandler.java | 10 +- .../inputmethod/event/CombinerChain.java | 14 +- .../inputmethod/event/MyanmarReordering.java | 3 +- .../inputmethod/keyboard/Keyboard.java | 9 +- .../keyboard/KeyboardLayoutSet.java | 9 +- .../inputmethod/keyboard/KeyboardView.java | 3 +- .../keyboard/MainKeyboardView.java | 4 +- .../inputmethod/keyboard/PointerTracker.java | 3 +- .../inputmethod/keyboard/ProximityInfo.java | 4 +- .../keyboard/emoji/DynamicGridKeyboard.java | 7 +- .../keyboard/emoji/EmojiCategory.java | 14 +- .../keyboard/emoji/EmojiPalettesAdapter.java | 4 +- .../internal/DrawingPreviewPlacerView.java | 3 +- .../internal/GestureTrailsDrawingPreview.java | 4 +- .../internal/KeyPreviewChoreographer.java | 7 +- .../keyboard/internal/KeyStylesSet.java | 5 +- .../keyboard/internal/KeyboardCodesSet.java | 3 +- .../keyboard/internal/KeyboardIconsSet.java | 3 +- .../keyboard/internal/KeyboardParams.java | 7 +- .../keyboard/internal/KeyboardRow.java | 3 +- .../keyboard/internal/KeyboardTextsSet.java | 3 +- .../keyboard/internal/KeyboardTextsTable.java | 10 +- .../keyboard/internal/KeysCache.java | 3 +- .../keyboard/internal/MoreKeySpec.java | 2 +- .../internal/PointerTrackerQueue.java | 4 +- .../inputmethod/latin/BinaryDictionary.java | 20 ++- .../latin/BinaryDictionaryFileDumper.java | 5 +- .../latin/BinaryDictionaryGetter.java | 5 +- .../latin/ContactsBinaryDictionary.java | 5 +- .../latin/DictionaryCollection.java | 11 +- .../latin/DictionaryFacilitator.java | 13 +- .../inputmethod/latin/DictionaryFactory.java | 3 +- .../latin/ExpandableBinaryDictionary.java | 3 +- .../inputmethod/latin/InputAttributes.java | 3 +- .../inputmethod/latin/LastComposedWord.java | 2 +- .../android/inputmethod/latin/LatinIME.java | 4 +- .../latin/PunctuationSuggestions.java | 4 +- .../latin/RichInputMethodManager.java | 5 +- .../inputmethod/latin/SubtypeSwitcher.java | 3 +- .../android/inputmethod/latin/Suggest.java | 12 +- .../inputmethod/latin/SuggestedWords.java | 14 +- .../inputmethod/latin/WordComposer.java | 3 +- .../ExternalDictionaryGetterForDebug.java | 3 +- .../latin/inputlogic/InputLogic.java | 9 +- .../latin/makedict/WordProperty.java | 5 +- .../latin/personalization/AccountUtils.java | 4 +- ...ecayingExpandableBinaryDictionaryBase.java | 1 - .../PersonalizationHelper.java | 15 +-- .../settings/AdditionalSubtypeSettings.java | 9 +- .../latin/settings/SettingsValues.java | 2 +- .../latin/setup/SetupWizardActivity.java | 3 +- .../AndroidSpellCheckerService.java | 10 +- .../AndroidSpellCheckerSession.java | 8 +- .../AndroidWordLevelSpellCheckerSession.java | 3 +- .../latin/spellcheck/DictAndKeyboard.java | 6 +- .../latin/spellcheck/DictionaryPool.java | 3 +- .../suggestions/SuggestionStripView.java | 7 +- .../UserDictionaryAddWordContents.java | 2 +- .../UserDictionaryAddWordFragment.java | 4 +- .../userdictionary/UserDictionaryList.java | 2 +- .../latin/utils/AdditionalSubtypeUtils.java | 3 +- .../latin/utils/AutoCorrectionUtils.java | 5 +- .../latin/utils/CollectionUtils.java | 76 +---------- .../inputmethod/latin/utils/CsvUtils.java | 2 +- .../latin/utils/DictionaryInfoUtils.java | 2 +- .../DistracterFilterUsingSuggestion.java | 2 +- .../latin/utils/ExecutorUtils.java | 5 +- .../latin/utils/FragmentUtils.java | 2 +- .../inputmethod/latin/utils/JsonUtils.java | 2 +- .../latin/utils/LanguageModelParam.java | 3 +- .../latin/utils/LeakGuardHandlerWrapper.java | 2 +- .../inputmethod/latin/utils/LocaleUtils.java | 2 +- .../utils/PrioritizedSerialExecutor.java | 4 +- .../latin/utils/ResourceUtils.java | 7 +- .../inputmethod/latin/utils/StringUtils.java | 3 +- .../latin/utils/SubtypeLocaleUtils.java | 13 +- .../utils/TargetPackageInfoGetterTask.java | 3 +- .../latin/utils/TypefaceUtils.java | 4 +- .../latin/utils/UserLogRingCharBuffer.java | 2 +- .../inputmethod/research/FixedLogBuffer.java | 2 +- .../inputmethod/research/LogBuffer.java | 2 +- .../android/inputmethod/research/LogUnit.java | 12 +- .../research/MotionEventReader.java | 14 +- .../keyboard/KeyboardLayoutSetTestsBase.java | 9 +- .../internal/KeyboardTextsSetTests.java | 3 +- .../internal/MoreKeySpecSplitTests.java | 4 +- .../expected/ActualKeyboardBuilder.java | 9 +- .../keyboard/layout/expected/ExpectedKey.java | 6 +- .../expected/ExpectedKeyboardBuilder.java | 4 +- .../latin/BinaryDictionaryDecayingTests.java | 12 +- .../latin/BinaryDictionaryTests.java | 121 ++++++++---------- .../InputLogicTestsLanguageWithoutSpaces.java | 2 - .../latin/InputLogicTestsNonEnglish.java | 2 - .../InputLogicTestsReorderingMyanmar.java | 2 + .../latin/LatinImeStressTests.java | 1 - .../latin/SuggestedWordsTests.java | 6 +- .../BinaryDictDecoderEncoderTests.java | 54 ++++---- .../makedict/BinaryDictDecoderUtils.java | 3 - .../makedict/BinaryDictEncoderUtils.java | 2 +- .../latin/makedict/BinaryDictIOUtils.java | 2 +- .../latin/makedict/FusionDictionary.java | 11 +- .../latin/makedict/Ver2DictDecoder.java | 9 +- .../latin/makedict/Ver2DictDecoderTests.java | 2 - .../latin/makedict/Ver4DictDecoder.java | 5 +- .../UserHistoryDictionaryTests.java | 7 +- .../latin/utils/AsyncResultHolderTests.java | 8 +- .../utils/BinaryDictionaryUtilsTests.java | 2 +- .../latin/utils/ResourceUtilsTests.java | 10 +- .../utils/SpacebarLanguagetUtilsTests.java | 2 +- .../latin/utils/SubtypeLocaleUtilsTests.java | 2 +- tools/dicttool/Android.mk | 1 - .../compat/android/util/SparseArray.java | 6 +- .../compat/android/util/SparseIntArray.java | 2 +- .../inputmethod/event/CombinerChain.java | 2 - .../dicttool/BinaryDictOffdeviceUtils.java | 5 +- .../latin/dicttool/CombinedInputOutput.java | 12 +- .../latin/dicttool/DictionaryMaker.java | 2 +- .../inputmethod/latin/dicttool/Dicttool.java | 3 +- .../inputmethod/latin/dicttool/Diff.java | 3 +- .../inputmethod/latin/dicttool/Test.java | 4 +- .../latin/dicttool/XmlDictInputOutput.java | 8 +- .../BinaryDictOffdeviceUtilsTests.java | 4 +- .../latin/makedict/FusionDictionaryTest.java | 2 +- .../keyboard/internal/KeyboardTextsTable.tmpl | 10 +- .../inputmethod/keyboard/tools/JarUtils.java | 2 +- .../keyboard/tools/LocaleUtils.java | 2 +- .../keyboard/tools/MakeKeyboardText.java | 2 +- .../keyboard/tools/MoreKeysResources.java | 7 +- .../keyboard/tools/StringResourceMap.java | 4 +- 141 files changed, 366 insertions(+), 592 deletions(-) diff --git a/java/proguard.flags b/java/proguard.flags index f7b7f2898..35b3ac3d3 100644 --- a/java/proguard.flags +++ b/java/proguard.flags @@ -17,7 +17,8 @@ # Keep classes that are used as a parameter type of methods that are also marked as keep # to preserve changing those methods' signature. --keep class com.android.inputmethod.latin.utils.LanguageModelParam -keep class com.android.inputmethod.latin.AssetFileAddress --keep class com.android.inputmethod.latin.makedict.ProbabilityInfo -keep class com.android.inputmethod.latin.Dictionary +-keep class com.android.inputmethod.latin.PrevWordsInfo +-keep class com.android.inputmethod.latin.makedict.ProbabilityInfo +-keep class com.android.inputmethod.latin.utils.LanguageModelParam diff --git a/java/src/com/android/inputmethod/accessibility/MainKeyboardAccessibilityDelegate.java b/java/src/com/android/inputmethod/accessibility/MainKeyboardAccessibilityDelegate.java index c114551c8..443f793a1 100644 --- a/java/src/com/android/inputmethod/accessibility/MainKeyboardAccessibilityDelegate.java +++ b/java/src/com/android/inputmethod/accessibility/MainKeyboardAccessibilityDelegate.java @@ -17,13 +17,8 @@ package com.android.inputmethod.accessibility; import android.content.Context; -import android.os.SystemClock; -import android.support.v4.view.accessibility.AccessibilityEventCompat; -import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat; import android.util.SparseIntArray; -import android.view.MotionEvent; -import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.KeyDetector; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardId; diff --git a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java index 60f7e2def..b92290600 100644 --- a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java +++ b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java @@ -27,7 +27,6 @@ import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestionSpanPickedNotificationReceiver; -import com.android.inputmethod.latin.utils.CollectionUtils; import java.lang.reflect.Field; import java.util.ArrayList; @@ -73,7 +72,7 @@ public final class SuggestionSpanUtils { return pickedWord; } - final ArrayList suggestionsList = CollectionUtils.newArrayList(); + final ArrayList suggestionsList = new ArrayList<>(); for (int i = 0; i < suggestedWords.size(); ++i) { if (suggestionsList.size() >= SuggestionSpan.SUGGESTIONS_MAX_SIZE) { break; diff --git a/java/src/com/android/inputmethod/dictionarypack/ActionBatch.java b/java/src/com/android/inputmethod/dictionarypack/ActionBatch.java index 3f69cedee..3d294acd7 100644 --- a/java/src/com/android/inputmethod/dictionarypack/ActionBatch.java +++ b/java/src/com/android/inputmethod/dictionarypack/ActionBatch.java @@ -16,7 +16,6 @@ package com.android.inputmethod.dictionarypack; -import android.app.DownloadManager; import android.app.DownloadManager.Request; import android.content.ContentValues; import android.content.Context; @@ -600,7 +599,7 @@ public final class ActionBatch { private final Queue mActions; public ActionBatch() { - mActions = new LinkedList(); + mActions = new LinkedList<>(); } public void add(final Action a) { diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java b/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java index 2623eff56..1d84e5888 100644 --- a/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java +++ b/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java @@ -29,7 +29,6 @@ import android.view.View; import android.widget.ProgressBar; public class DictionaryDownloadProgressBar extends ProgressBar { - @SuppressWarnings("unused") private static final String TAG = DictionaryDownloadProgressBar.class.getSimpleName(); private static final int NOT_A_DOWNLOADMANAGER_PENDING_ID = 0; @@ -119,7 +118,6 @@ public class DictionaryDownloadProgressBar extends ProgressBar { try { final UpdateHelper updateHelper = new UpdateHelper(); final Query query = new Query().setFilterById(mId); - int lastProgress = 0; setIndeterminate(true); while (!isInterrupted()) { final Cursor cursor = mDownloadManagerWrapper.query(query); diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java b/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java index 13c07de35..8e026171d 100644 --- a/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java +++ b/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java @@ -18,8 +18,6 @@ package com.android.inputmethod.dictionarypack; import android.view.View; -import com.android.inputmethod.latin.utils.CollectionUtils; - import java.util.ArrayList; import java.util.HashMap; @@ -39,8 +37,8 @@ public class DictionaryListInterfaceState { public int mStatus = MetadataDbHelper.STATUS_UNKNOWN; } - private HashMap mWordlistToState = CollectionUtils.newHashMap(); - private ArrayList mViewCache = CollectionUtils.newArrayList(); + private HashMap mWordlistToState = new HashMap<>(); + private ArrayList mViewCache = new ArrayList<>(); public boolean isOpen(final String wordlistId) { final State state = mWordlistToState.get(wordlistId); diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionaryProvider.java b/java/src/com/android/inputmethod/dictionarypack/DictionaryProvider.java index c35995b24..f5bd84c8c 100644 --- a/java/src/com/android/inputmethod/dictionarypack/DictionaryProvider.java +++ b/java/src/com/android/inputmethod/dictionarypack/DictionaryProvider.java @@ -357,7 +357,7 @@ public final class DictionaryProvider extends ContentProvider { return Collections.emptyList(); } try { - final HashMap dicts = new HashMap(); + final HashMap dicts = new HashMap<>(); final int idIndex = results.getColumnIndex(MetadataDbHelper.WORDLISTID_COLUMN); final int localeIndex = results.getColumnIndex(MetadataDbHelper.LOCALE_COLUMN); final int localFileNameIndex = diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java b/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java index dae2f22a4..11982fa65 100644 --- a/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java +++ b/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java @@ -33,13 +33,13 @@ import android.preference.PreferenceGroup; import android.text.TextUtils; import android.text.format.DateUtils; import android.util.Log; -import android.view.animation.AnimationUtils; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.animation.AnimationUtils; import com.android.inputmethod.latin.R; @@ -67,8 +67,8 @@ public final class DictionarySettingsFragment extends PreferenceFragment private boolean mChangedSettings; private DictionaryListInterfaceState mDictionaryListInterfaceState = new DictionaryListInterfaceState(); - private TreeMap mCurrentPreferenceMap = - new TreeMap(); // never null + // never null + private TreeMap mCurrentPreferenceMap = new TreeMap<>(); private final BroadcastReceiver mConnectivityChangedReceiver = new BroadcastReceiver() { @Override @@ -280,19 +280,18 @@ public final class DictionarySettingsFragment extends PreferenceFragment : activity.getContentResolver().query(contentUri, null, null, null, null); if (null == cursor) { - final ArrayList result = new ArrayList(); + final ArrayList result = new ArrayList<>(); result.add(createErrorMessage(activity, R.string.cannot_connect_to_dict_service)); return result; } try { if (!cursor.moveToFirst()) { - final ArrayList result = new ArrayList(); + final ArrayList result = new ArrayList<>(); result.add(createErrorMessage(activity, R.string.no_dictionaries_available)); return result; } else { final String systemLocaleString = Locale.getDefault().toString(); - final TreeMap prefMap = - new TreeMap(); + final TreeMap prefMap = new TreeMap<>(); final int idIndex = cursor.getColumnIndex(MetadataDbHelper.WORDLISTID_COLUMN); final int versionIndex = cursor.getColumnIndex(MetadataDbHelper.VERSION_COLUMN); final int localeIndex = cursor.getColumnIndex(MetadataDbHelper.LOCALE_COLUMN); diff --git a/java/src/com/android/inputmethod/dictionarypack/LocaleUtils.java b/java/src/com/android/inputmethod/dictionarypack/LocaleUtils.java index 77f67b8a3..4f0805c5c 100644 --- a/java/src/com/android/inputmethod/dictionarypack/LocaleUtils.java +++ b/java/src/com/android/inputmethod/dictionarypack/LocaleUtils.java @@ -175,7 +175,7 @@ public final class LocaleUtils { return saveLocale; } - private static final HashMap sLocaleCache = new HashMap(); + private static final HashMap sLocaleCache = new HashMap<>(); /** * Creates a locale from a string specification. diff --git a/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java b/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java index 743bc8037..17dd781d5 100644 --- a/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java +++ b/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java @@ -160,7 +160,7 @@ public class MetadataDbHelper extends SQLiteOpenHelper { // this legacy database. New clients should make sure to always pass a client ID so as // to avoid conflicts. final String clientId = null != clientIdOrNull ? clientIdOrNull : ""; - if (null == sInstanceMap) sInstanceMap = new TreeMap(); + if (null == sInstanceMap) sInstanceMap = new TreeMap<>(); MetadataDbHelper helper = sInstanceMap.get(clientId); if (null == helper) { helper = new MetadataDbHelper(context, clientId); @@ -639,7 +639,7 @@ public class MetadataDbHelper extends SQLiteOpenHelper { public static ArrayList getDownloadRecordsForDownloadId(final Context context, final long downloadId) { final SQLiteDatabase defaultDb = getDb(context, ""); - final ArrayList results = new ArrayList(); + final ArrayList results = new ArrayList<>(); final Cursor cursor = defaultDb.query(CLIENT_TABLE_NAME, CLIENT_TABLE_COLUMNS, null, null, null, null, null); try { @@ -923,7 +923,7 @@ public class MetadataDbHelper extends SQLiteOpenHelper { // - Remove the old entry from the table // - Erase the old file // We start by gathering the names of the files we should delete. - final List filenames = new LinkedList(); + final List filenames = new LinkedList<>(); final Cursor c = db.query(METADATA_TABLE_NAME, new String[] { LOCAL_FILENAME_COLUMN }, LOCALE_COLUMN + " = ? AND " + diff --git a/java/src/com/android/inputmethod/dictionarypack/MetadataHandler.java b/java/src/com/android/inputmethod/dictionarypack/MetadataHandler.java index 63e419871..d66b69050 100644 --- a/java/src/com/android/inputmethod/dictionarypack/MetadataHandler.java +++ b/java/src/com/android/inputmethod/dictionarypack/MetadataHandler.java @@ -43,7 +43,7 @@ public class MetadataHandler { * @return the constructed list of wordlist metadata. */ private static List makeMetadataObject(final Cursor results) { - final ArrayList buildingMetadata = new ArrayList(); + final ArrayList buildingMetadata = new ArrayList<>(); if (null != results && results.moveToFirst()) { final int localeColumn = results.getColumnIndex(MetadataDbHelper.LOCALE_COLUMN); final int typeColumn = results.getColumnIndex(MetadataDbHelper.TYPE_COLUMN); diff --git a/java/src/com/android/inputmethod/dictionarypack/MetadataParser.java b/java/src/com/android/inputmethod/dictionarypack/MetadataParser.java index a88173e8e..52290cadc 100644 --- a/java/src/com/android/inputmethod/dictionarypack/MetadataParser.java +++ b/java/src/com/android/inputmethod/dictionarypack/MetadataParser.java @@ -52,7 +52,7 @@ public class MetadataParser { */ private static WordListMetadata parseOneWordList(final JsonReader reader) throws IOException, BadFormatException { - final TreeMap arguments = new TreeMap(); + final TreeMap arguments = new TreeMap<>(); reader.beginObject(); while (reader.hasNext()) { final String name = reader.nextName(); @@ -100,7 +100,7 @@ public class MetadataParser { public static List parseMetadata(final InputStreamReader input) throws IOException, BadFormatException { JsonReader reader = new JsonReader(input); - final ArrayList readInfo = new ArrayList(); + final ArrayList readInfo = new ArrayList<>(); reader.beginArray(); while (reader.hasNext()) { final WordListMetadata thisMetadata = parseOneWordList(reader); diff --git a/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java b/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java index dcff490db..95a094232 100644 --- a/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java +++ b/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java @@ -177,7 +177,7 @@ public final class UpdateHandler { */ public static boolean tryUpdate(final Context context, final boolean updateNow) { // TODO: loop through all clients instead of only doing the default one. - final TreeSet uris = new TreeSet(); + final TreeSet uris = new TreeSet<>(); final Cursor cursor = MetadataDbHelper.queryClientIds(context); if (null == cursor) return false; try { @@ -557,7 +557,7 @@ public final class UpdateHandler { // Instantiation of a parameterized type is not possible in Java, so it's not possible to // return the same type of list that was passed - probably the same reason why Collections // does not do it. So we need to decide statically which concrete type to return. - return new LinkedList(src); + return new LinkedList<>(src); } /** @@ -740,10 +740,10 @@ public final class UpdateHandler { final ActionBatch actions = new ActionBatch(); // Upgrade existing word lists DebugLogUtils.l("Comparing dictionaries"); - final Set wordListIds = new TreeSet(); + final Set wordListIds = new TreeSet<>(); // TODO: Can these be null? - if (null == from) from = new ArrayList(); - if (null == to) to = new ArrayList(); + if (null == from) from = new ArrayList<>(); + if (null == to) to = new ArrayList<>(); for (WordListMetadata wlData : from) wordListIds.add(wlData.mId); for (WordListMetadata wlData : to) wordListIds.add(wlData.mId); for (String id : wordListIds) { diff --git a/java/src/com/android/inputmethod/event/CombinerChain.java b/java/src/com/android/inputmethod/event/CombinerChain.java index 9e7f04d4f..61bc11b39 100644 --- a/java/src/com/android/inputmethod/event/CombinerChain.java +++ b/java/src/com/android/inputmethod/event/CombinerChain.java @@ -20,7 +20,6 @@ import android.text.SpannableStringBuilder; import android.text.TextUtils; import com.android.inputmethod.latin.Constants; -import com.android.inputmethod.latin.utils.CollectionUtils; import java.util.ArrayList; import java.util.HashMap; @@ -44,8 +43,8 @@ public class CombinerChain { private SpannableStringBuilder mStateFeedback; private final ArrayList mCombiners; - private static final HashMap IMPLEMENTED_COMBINERS - = new HashMap(); + private static final HashMap> IMPLEMENTED_COMBINERS = + new HashMap<>(); static { IMPLEMENTED_COMBINERS.put("MyanmarReordering", MyanmarReordering.class); } @@ -63,7 +62,7 @@ public class CombinerChain { * @param combinerList A list of combiners to be applied in order. */ public CombinerChain(final String initialText, final Combiner... combinerList) { - mCombiners = CollectionUtils.newArrayList(); + mCombiners = new ArrayList<>(); // The dead key combiner is always active, and always first mCombiners.add(new DeadKeyCombiner()); for (final Combiner combiner : combinerList) { @@ -87,7 +86,7 @@ public class CombinerChain { * @param newEvent the new event to process */ public void processEvent(final ArrayList previousEvents, final Event newEvent) { - final ArrayList modifiablePreviousEvents = new ArrayList(previousEvents); + final ArrayList modifiablePreviousEvents = new ArrayList<>(previousEvents); Event event = newEvent; for (final Combiner combiner : mCombiners) { // A combiner can never return more than one event; it can return several @@ -136,12 +135,13 @@ public class CombinerChain { final Combiner[] combiners = new Combiner[combinerDescriptors.length]; int i = 0; for (final String combinerDescriptor : combinerDescriptors) { - final Class combinerClass = IMPLEMENTED_COMBINERS.get(combinerDescriptor); + final Class combinerClass = + IMPLEMENTED_COMBINERS.get(combinerDescriptor); if (null == combinerClass) { throw new RuntimeException("Unknown combiner descriptor: " + combinerDescriptor); } try { - combiners[i++] = (Combiner)combinerClass.newInstance(); + combiners[i++] = combinerClass.newInstance(); } catch (InstantiationException e) { throw new RuntimeException("Unable to instantiate combiner: " + combinerDescriptor, e); diff --git a/java/src/com/android/inputmethod/event/MyanmarReordering.java b/java/src/com/android/inputmethod/event/MyanmarReordering.java index da0228bd2..32919932d 100644 --- a/java/src/com/android/inputmethod/event/MyanmarReordering.java +++ b/java/src/com/android/inputmethod/event/MyanmarReordering.java @@ -17,7 +17,6 @@ package com.android.inputmethod.event; import com.android.inputmethod.latin.Constants; -import com.android.inputmethod.latin.utils.CollectionUtils; import java.util.ArrayList; import java.util.Arrays; @@ -32,7 +31,7 @@ public class MyanmarReordering implements Combiner { // U+200B ZERO WIDTH SPACE private final static int ZERO_WIDTH_NON_JOINER = 0x200B; // should be 0x200C - private final ArrayList mCurrentEvents = CollectionUtils.newArrayList(); + private final ArrayList mCurrentEvents = new ArrayList<>(); // List of consonants : // U+1000 MYANMAR LETTER KA diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index f646a03c2..85dfea4e7 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -22,9 +22,9 @@ import com.android.inputmethod.keyboard.internal.KeyVisualAttributes; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.keyboard.internal.KeyboardParams; import com.android.inputmethod.latin.Constants; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.CoordinateUtils; +import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -83,7 +83,7 @@ public class Keyboard { public final List mAltCodeKeysWhileTyping; public final KeyboardIconsSet mIconsSet; - private final SparseArray mKeyCache = CollectionUtils.newSparseArray(); + private final SparseArray mKeyCache = new SparseArray<>(); private final ProximityInfo mProximityInfo; private final boolean mProximityCharsCorrectionEnabled; @@ -103,8 +103,7 @@ public class Keyboard { mTopPadding = params.mTopPadding; mVerticalGap = params.mVerticalGap; - mSortedKeys = Collections.unmodifiableList( - CollectionUtils.newArrayList(params.mSortedKeys)); + mSortedKeys = Collections.unmodifiableList(new ArrayList<>(params.mSortedKeys)); mShiftKeys = Collections.unmodifiableList(params.mShiftKeys); mAltCodeKeysWhileTyping = Collections.unmodifiableList(params.mAltCodeKeysWhileTyping); mIconsSet = params.mIconsSet; @@ -159,7 +158,7 @@ public class Keyboard { /** * Return the sorted list of keys of this keyboard. * The keys are sorted from top-left to bottom-right order. - * The list may contain {@link Spacer} object as well. + * The list may contain {@link Key.Spacer} object as well. * @return the sorted unmodifiable list of {@link Key}s of this keyboard. */ public List getSortedKeys() { diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java index cde5091c4..aa646994c 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java @@ -41,7 +41,6 @@ import com.android.inputmethod.latin.InputAttributes; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SubtypeSwitcher; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.InputTypeUtils; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; import com.android.inputmethod.latin.utils.XmlParseUtils; @@ -81,7 +80,7 @@ public final class KeyboardLayoutSet { // them from disappearing from sKeyboardCache. private static final Keyboard[] sForcibleKeyboardCache = new Keyboard[FORCIBLE_CACHE_SIZE]; private static final HashMap> sKeyboardCache = - CollectionUtils.newHashMap(); + new HashMap<>(); private static final KeysCache sKeysCache = new KeysCache(); @SuppressWarnings("serial") @@ -117,7 +116,7 @@ public final class KeyboardLayoutSet { int mKeyboardHeight; // Sparse array of KeyboardLayoutSet element parameters indexed by element's id. final SparseArray mKeyboardLayoutSetElementIdToParamsMap = - CollectionUtils.newSparseArray(); + new SparseArray<>(); } public static void clearKeyboardCache() { @@ -181,7 +180,7 @@ public final class KeyboardLayoutSet { } final KeyboardBuilder builder = - new KeyboardBuilder(mContext, new KeyboardParams()); + new KeyboardBuilder<>(mContext, new KeyboardParams()); if (id.isAlphabetKeyboard()) { builder.setAutoGenerate(sKeysCache); } @@ -192,7 +191,7 @@ public final class KeyboardLayoutSet { } builder.setProximityCharsCorrectionEnabled(elementParams.mProximityCharsCorrectionEnabled); final Keyboard keyboard = builder.build(); - sKeyboardCache.put(id, new SoftReference(keyboard)); + sKeyboardCache.put(id, new SoftReference<>(keyboard)); if ((id.mElementId == KeyboardId.ELEMENT_ALPHABET || id.mElementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) && !mParams.mIsSpellChecker) { diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index edfc5fded..f90ad7975 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -38,7 +38,6 @@ import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.define.ProductionFlag; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.TypefaceUtils; import com.android.inputmethod.research.ResearchLogger; @@ -110,7 +109,7 @@ public class KeyboardView extends View { /** True if all keys should be drawn */ private boolean mInvalidateAllKeys; /** The keys that should be drawn */ - private final HashSet mInvalidatedKeys = CollectionUtils.newHashSet(); + private final HashSet mInvalidatedKeys = new HashSet<>(); /** The working rectangle variable */ private final Rect mWorkingRect = new Rect(); /** The keyboard bitmap buffer for faster updates */ diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index 86036ccc1..22c6b6e0a 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -57,7 +57,6 @@ import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.settings.DebugSettings; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.CoordinateUtils; import com.android.inputmethod.latin.utils.SpacebarLanguageUtils; import com.android.inputmethod.latin.utils.TypefaceUtils; @@ -150,8 +149,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack private final Paint mBackgroundDimAlphaPaint = new Paint(); private boolean mNeedsToDimEntireKeyboard; private final View mMoreKeysKeyboardContainer; - private final WeakHashMap mMoreKeysKeyboardCache = - CollectionUtils.newWeakHashMap(); + private final WeakHashMap mMoreKeysKeyboardCache = new WeakHashMap<>(); private final boolean mConfigShowMoreKeysKeyboardAtTouchedPoint; // More keys panel (used by both more keys keyboard and more suggestions view) // TODO: Consider extending to support multiple more keys panels diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 4777166ea..303886cd3 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -37,7 +37,6 @@ import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.settings.Settings; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.CoordinateUtils; import com.android.inputmethod.latin.utils.ResourceUtils; import com.android.inputmethod.research.ResearchLogger; @@ -144,7 +143,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element, // TODO: Device specific parameter would be better for device specific hack? private static final float PHANTOM_SUDDEN_MOVE_THRESHOLD = 0.25f; // in keyWidth - private static final ArrayList sTrackers = CollectionUtils.newArrayList(); + private static final ArrayList sTrackers = new ArrayList<>(); private static final PointerTrackerQueue sPointerTrackerQueue = new PointerTrackerQueue(); public final int mPointerId; diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java index c89bda40e..c19cd671a 100644 --- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java +++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java @@ -22,7 +22,6 @@ import android.util.Log; import com.android.inputmethod.keyboard.internal.TouchPositionCorrection; import com.android.inputmethod.latin.Constants; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.JniUtils; import java.util.ArrayList; @@ -55,6 +54,7 @@ public class ProximityInfo { private final List[] mGridNeighbors; private final String mLocaleStr; + @SuppressWarnings("unchecked") ProximityInfo(final String localeStr, final int gridWidth, final int gridHeight, final int minWidth, final int height, final int mostCommonKeyWidth, final int mostCommonKeyHeight, final List sortedKeys, @@ -360,7 +360,7 @@ y |---+---+---+---+-v-+-|-+---+---+---+---+---| | thresholdBase and get for (int i = 0; i < gridSize; ++i) { final int indexStart = i * keyCount; final int indexEnd = indexStart + neighborCountPerCell[i]; - final ArrayList neighbors = CollectionUtils.newArrayList(indexEnd - indexStart); + final ArrayList neighbors = new ArrayList<>(indexEnd - indexStart); for (int index = indexStart; index < indexEnd; index++) { neighbors.add(neighborsFlatBuffer[index]); } diff --git a/java/src/com/android/inputmethod/keyboard/emoji/DynamicGridKeyboard.java b/java/src/com/android/inputmethod/keyboard/emoji/DynamicGridKeyboard.java index c7a9025c0..daeb1f928 100644 --- a/java/src/com/android/inputmethod/keyboard/emoji/DynamicGridKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/emoji/DynamicGridKeyboard.java @@ -23,7 +23,6 @@ import android.util.Log; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.latin.settings.Settings; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.JsonUtils; import java.util.ArrayDeque; @@ -47,8 +46,8 @@ final class DynamicGridKeyboard extends Keyboard { private final int mColumnsNum; private final int mMaxKeyCount; private final boolean mIsRecents; - private final ArrayDeque mGridKeys = CollectionUtils.newArrayDeque(); - private final ArrayDeque mPendingKeys = CollectionUtils.newArrayDeque(); + private final ArrayDeque mGridKeys = new ArrayDeque<>(); + private final ArrayDeque mPendingKeys = new ArrayDeque<>(); private List mCachedGridKeys; @@ -131,7 +130,7 @@ final class DynamicGridKeyboard extends Keyboard { } private void saveRecentKeys() { - final ArrayList keys = CollectionUtils.newArrayList(); + final ArrayList keys = new ArrayList<>(); for (final Key key : mGridKeys) { if (key.getOutputText() != null) { keys.add(key.getOutputText()); diff --git a/java/src/com/android/inputmethod/keyboard/emoji/EmojiCategory.java b/java/src/com/android/inputmethod/keyboard/emoji/EmojiCategory.java index 859099110..512d4615d 100644 --- a/java/src/com/android/inputmethod/keyboard/emoji/EmojiCategory.java +++ b/java/src/com/android/inputmethod/keyboard/emoji/EmojiCategory.java @@ -31,7 +31,6 @@ import com.android.inputmethod.keyboard.KeyboardLayoutSet; import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.settings.Settings; -import com.android.inputmethod.latin.utils.CollectionUtils; import java.util.ArrayList; import java.util.Collections; @@ -101,12 +100,11 @@ final class EmojiCategory { private final Resources mRes; private final int mMaxPageKeyCount; private final KeyboardLayoutSet mLayoutSet; - private final HashMap mCategoryNameToIdMap = CollectionUtils.newHashMap(); + private final HashMap mCategoryNameToIdMap = new HashMap<>(); private final int[] mCategoryTabIconId = new int[sCategoryName.length]; - private final ArrayList mShownCategories = - CollectionUtils.newArrayList(); - private final ConcurrentHashMap - mCategoryKeyboardMap = new ConcurrentHashMap(); + private final ArrayList mShownCategories = new ArrayList<>(); + private final ConcurrentHashMap mCategoryKeyboardMap = + new ConcurrentHashMap<>(); private int mCurrentCategoryId = EmojiCategory.ID_UNSPECIFIED; private int mCurrentCategoryPageId = 0; @@ -257,7 +255,7 @@ final class EmojiCategory { final int temp = sum; sum += properties.mPageCount; if (sum > position) { - return new Pair(properties.mCategoryId, position - temp); + return new Pair<>(properties.mCategoryId, position - temp); } } return null; @@ -343,7 +341,7 @@ final class EmojiCategory { }; private static Key[][] sortKeysIntoPages(final List inKeys, final int maxPageCount) { - final ArrayList keys = CollectionUtils.newArrayList(inKeys); + final ArrayList keys = new ArrayList<>(inKeys); Collections.sort(keys, EMOJI_KEY_COMPARATOR); final int pageCount = (keys.size() - 1) / maxPageCount + 1; final Key[][] retval = new Key[pageCount][maxPageCount]; diff --git a/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesAdapter.java b/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesAdapter.java index 52a4dde97..b1e6dd318 100644 --- a/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesAdapter.java +++ b/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesAdapter.java @@ -27,7 +27,6 @@ import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.utils.CollectionUtils; final class EmojiPalettesAdapter extends PagerAdapter { private static final String TAG = EmojiPalettesAdapter.class.getSimpleName(); @@ -35,8 +34,7 @@ final class EmojiPalettesAdapter extends PagerAdapter { private final EmojiPageKeyboardView.OnKeyEventListener mListener; private final DynamicGridKeyboard mRecentsKeyboard; - private final SparseArray mActiveKeyboardViews = - CollectionUtils.newSparseArray(); + private final SparseArray mActiveKeyboardViews = new SparseArray<>(); private final EmojiCategory mEmojiCategory; private int mActivePosition = 0; diff --git a/java/src/com/android/inputmethod/keyboard/internal/DrawingPreviewPlacerView.java b/java/src/com/android/inputmethod/keyboard/internal/DrawingPreviewPlacerView.java index fdc2458d4..3b4c43418 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/DrawingPreviewPlacerView.java +++ b/java/src/com/android/inputmethod/keyboard/internal/DrawingPreviewPlacerView.java @@ -24,7 +24,6 @@ import android.graphics.PorterDuffXfermode; import android.util.AttributeSet; import android.widget.RelativeLayout; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.CoordinateUtils; import java.util.ArrayList; @@ -32,7 +31,7 @@ import java.util.ArrayList; public final class DrawingPreviewPlacerView extends RelativeLayout { private final int[] mKeyboardViewOrigin = CoordinateUtils.newInstance(); - private final ArrayList mPreviews = CollectionUtils.newArrayList(); + private final ArrayList mPreviews = new ArrayList<>(); public DrawingPreviewPlacerView(final Context context, final AttributeSet attrs) { super(context, attrs); diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsDrawingPreview.java b/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsDrawingPreview.java index d8b00c707..72628e38a 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsDrawingPreview.java +++ b/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsDrawingPreview.java @@ -29,15 +29,13 @@ import android.util.SparseArray; import android.view.View; import com.android.inputmethod.keyboard.PointerTracker; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper; /** * Draw preview graphics of multiple gesture trails during gesture input. */ public final class GestureTrailsDrawingPreview extends AbstractDrawingPreview { - private final SparseArray mGestureTrails = - CollectionUtils.newSparseArray(); + private final SparseArray mGestureTrails = new SparseArray<>(); private final GestureTrailDrawingParams mDrawingParams; private final Paint mGesturePaint; private int mOffscreenWidth; diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java b/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java index 625d1f0a4..605519b02 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java @@ -32,7 +32,6 @@ import android.widget.TextView; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.CoordinateUtils; import com.android.inputmethod.latin.utils.ViewLayoutUtils; @@ -48,9 +47,9 @@ import java.util.HashSet; */ public final class KeyPreviewChoreographer { // Free {@link TextView} pool that can be used for key preview. - private final ArrayDeque mFreeKeyPreviewTextViews = CollectionUtils.newArrayDeque(); + private final ArrayDeque mFreeKeyPreviewTextViews = new ArrayDeque<>(); // Map from {@link Key} to {@link TextView} that is currently being displayed as key preview. - private final HashMap mShowingKeyPreviewTextViews = CollectionUtils.newHashMap(); + private final HashMap mShowingKeyPreviewTextViews = new HashMap<>(); private final KeyPreviewDrawParams mParams; @@ -83,7 +82,7 @@ public final class KeyPreviewChoreographer { } public void dismissAllKeyPreviews() { - for (final Key key : new HashSet(mShowingKeyPreviewTextViews.keySet())) { + for (final Key key : new HashSet<>(mShowingKeyPreviewTextViews.keySet())) { dismissKeyPreview(key, false /* withAnimation */); } } diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyStylesSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyStylesSet.java index 700c9b07c..0b0e761d2 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyStylesSet.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyStylesSet.java @@ -21,7 +21,6 @@ import android.util.Log; import android.util.SparseArray; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.XmlParseUtils; import org.xmlpull.v1.XmlPullParser; @@ -34,7 +33,7 @@ public final class KeyStylesSet { private static final String TAG = KeyStylesSet.class.getSimpleName(); private static final boolean DEBUG = false; - private final HashMap mStyles = CollectionUtils.newHashMap(); + private final HashMap mStyles = new HashMap<>(); private final KeyboardTextsSet mTextsSet; private final KeyStyle mEmptyKeyStyle; @@ -75,7 +74,7 @@ public final class KeyStylesSet { private static final class DeclaredKeyStyle extends KeyStyle { private final HashMap mStyles; private final String mParentStyleName; - private final SparseArray mStyleAttributes = CollectionUtils.newSparseArray(); + private final SparseArray mStyleAttributes = new SparseArray<>(); public DeclaredKeyStyle(final String parentStyleName, final KeyboardTextsSet textsSet, final HashMap styles) { diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java index 06da5719b..62b69dcc9 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java @@ -17,14 +17,13 @@ package com.android.inputmethod.keyboard.internal; import com.android.inputmethod.latin.Constants; -import com.android.inputmethod.latin.utils.CollectionUtils; import java.util.HashMap; public final class KeyboardCodesSet { public static final String PREFIX_CODE = "!code/"; - private static final HashMap sNameToIdMap = CollectionUtils.newHashMap(); + private static final HashMap sNameToIdMap = new HashMap<>(); private KeyboardCodesSet() { // This utility class is not publicly instantiable. diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java index b5a94807e..916c4e1a7 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java @@ -23,7 +23,6 @@ import android.util.Log; import android.util.SparseIntArray; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.utils.CollectionUtils; import java.util.HashMap; @@ -60,7 +59,7 @@ public final class KeyboardIconsSet { private static final SparseIntArray ATTR_ID_TO_ICON_ID = new SparseIntArray(); // Icon name to icon id map. - private static final HashMap sNameToIdsMap = CollectionUtils.newHashMap(); + private static final HashMap sNameToIdsMap = new HashMap<>(); private static final Object[] NAMES_AND_ATTR_IDS = { NAME_UNDEFINED, ATTR_UNDEFINED, diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java index a61a79b85..5df9d3ece 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java @@ -21,7 +21,6 @@ import android.util.SparseIntArray; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.latin.Constants; -import com.android.inputmethod.latin.utils.CollectionUtils; import java.util.ArrayList; import java.util.Comparator; @@ -61,9 +60,9 @@ public class KeyboardParams { public int GRID_HEIGHT; // Keys are sorted from top-left to bottom-right order. - public final SortedSet mSortedKeys = new TreeSet(ROW_COLUMN_COMPARATOR); - public final ArrayList mShiftKeys = CollectionUtils.newArrayList(); - public final ArrayList mAltCodeKeysWhileTyping = CollectionUtils.newArrayList(); + public final SortedSet mSortedKeys = new TreeSet<>(ROW_COLUMN_COMPARATOR); + public final ArrayList mShiftKeys = new ArrayList<>(); + public final ArrayList mAltCodeKeysWhileTyping = new ArrayList<>(); public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet(); public final KeyboardTextsSet mTextsSet = new KeyboardTextsSet(); public final KeyStylesSet mKeyStyles = new KeyStylesSet(mTextsSet); diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardRow.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardRow.java index 0f9497c27..6db1d02c9 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardRow.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardRow.java @@ -23,7 +23,6 @@ import android.util.Xml; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.ResourceUtils; import org.xmlpull.v1.XmlPullParser; @@ -44,7 +43,7 @@ public final class KeyboardRow { /** The height of this row. */ private final int mRowHeight; - private final ArrayDeque mRowAttributesStack = CollectionUtils.newArrayDeque(); + private final ArrayDeque mRowAttributesStack = new ArrayDeque<>(); private static class RowAttributes { /** Default width of a key in this row. */ diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java index 0047aa4a1..2ec5bcc97 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java @@ -22,7 +22,6 @@ import android.text.TextUtils; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.Constants; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.RunInLocale; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; @@ -38,7 +37,7 @@ public final class KeyboardTextsSet { private String[] mTextsTable; // Resource name to text map. - private HashMap mResourceNameToTextsMap = CollectionUtils.newHashMap(); + private HashMap mResourceNameToTextsMap = new HashMap<>(); public void setLocale(final Locale locale, final Context context) { mTextsTable = KeyboardTextsTable.getTextsTable(locale); diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.java index 7e6181a4e..40c915c8d 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.java @@ -16,8 +16,6 @@ package com.android.inputmethod.keyboard.internal; -import com.android.inputmethod.latin.utils.CollectionUtils; - import java.util.HashMap; import java.util.Locale; @@ -44,14 +42,12 @@ import java.util.Locale; */ public final class KeyboardTextsTable { // Name to index map. - private static final HashMap sNameToIndexesMap = CollectionUtils.newHashMap(); + private static final HashMap sNameToIndexesMap = new HashMap<>(); // Locale to texts table map. - private static final HashMap sLocaleToTextsTableMap = - CollectionUtils.newHashMap(); + private static final HashMap sLocaleToTextsTableMap = new HashMap<>(); // TODO: Remove this variable after debugging. // Texts table to locale maps. - private static final HashMap sTextsTableToLocaleMap = - CollectionUtils.newHashMap(); + private static final HashMap sTextsTableToLocaleMap = new HashMap<>(); public static String getText(final String name, final String[] textsTable) { final Integer indexObj = sNameToIndexesMap.get(name); diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeysCache.java b/java/src/com/android/inputmethod/keyboard/internal/KeysCache.java index 7c2e3e174..7743d4744 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeysCache.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeysCache.java @@ -17,12 +17,11 @@ package com.android.inputmethod.keyboard.internal; import com.android.inputmethod.keyboard.Key; -import com.android.inputmethod.latin.utils.CollectionUtils; import java.util.HashMap; public final class KeysCache { - private final HashMap mMap = CollectionUtils.newHashMap(); + private final HashMap mMap = new HashMap<>(); public void clear() { mMap.clear(); diff --git a/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpec.java b/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpec.java index 56ef4767f..e0d5173ac 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpec.java +++ b/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpec.java @@ -149,7 +149,7 @@ public final class MoreKeySpec { // Skip empty entry. if (pos - start > 0) { if (list == null) { - list = CollectionUtils.newArrayList(); + list = new ArrayList<>(); } list.add(text.substring(start, pos)); } diff --git a/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java b/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java index 5ac34188c..8e89e61ea 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java +++ b/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java @@ -18,8 +18,6 @@ package com.android.inputmethod.keyboard.internal; import android.util.Log; -import com.android.inputmethod.latin.utils.CollectionUtils; - import java.util.ArrayList; public final class PointerTrackerQueue { @@ -37,7 +35,7 @@ public final class PointerTrackerQueue { // Note: {@link #mExpandableArrayOfActivePointers} and {@link #mArraySize} are synchronized by // {@link #mExpandableArrayOfActivePointers} private final ArrayList mExpandableArrayOfActivePointers = - CollectionUtils.newArrayList(INITIAL_CAPACITY); + new ArrayList<>(INITIAL_CAPACITY); private int mArraySize = 0; public int size() { diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index b77540622..ef269b87d 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -30,7 +30,6 @@ import com.android.inputmethod.latin.makedict.UnsupportedFormatException; import com.android.inputmethod.latin.makedict.WordProperty; import com.android.inputmethod.latin.settings.NativeSuggestOptions; import com.android.inputmethod.latin.utils.BinaryDictionaryUtils; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.FileUtils; import com.android.inputmethod.latin.utils.JniUtils; import com.android.inputmethod.latin.utils.LanguageModelParam; @@ -104,8 +103,7 @@ public final class BinaryDictionary extends Dictionary { private final NativeSuggestOptions mNativeSuggestOptions = new NativeSuggestOptions(); - private final SparseArray mDicTraverseSessions = - CollectionUtils.newSparseArray(); + private final SparseArray mDicTraverseSessions = new SparseArray<>(); // TODO: There should be a way to remove used DicTraverseSession objects from // {@code mDicTraverseSessions}. @@ -248,11 +246,11 @@ public final class BinaryDictionary extends Dictionary { } final int[] outHeaderSize = new int[1]; final int[] outFormatVersion = new int[1]; - final ArrayList outAttributeKeys = CollectionUtils.newArrayList(); - final ArrayList outAttributeValues = CollectionUtils.newArrayList(); + final ArrayList outAttributeKeys = new ArrayList<>(); + final ArrayList outAttributeValues = new ArrayList<>(); getHeaderInfoNative(mNativeDict, outHeaderSize, outFormatVersion, outAttributeKeys, outAttributeValues); - final HashMap attributes = new HashMap(); + final HashMap attributes = new HashMap<>(); for (int i = 0; i < outAttributeKeys.size(); i++) { final String attributeKey = StringUtils.getStringFromNullTerminatedCodePointArray( outAttributeKeys.get(i)); @@ -312,7 +310,7 @@ public final class BinaryDictionary extends Dictionary { inOutLanguageWeight[0] = mInputOutputLanguageWeight[0]; } final int count = mOutputSuggestionCount[0]; - final ArrayList suggestions = CollectionUtils.newArrayList(); + final ArrayList suggestions = new ArrayList<>(); for (int j = 0; j < count; ++j) { final int start = j * MAX_WORD_LENGTH; int len = 0; @@ -386,10 +384,10 @@ public final class BinaryDictionary extends Dictionary { final boolean[] outFlags = new boolean[FORMAT_WORD_PROPERTY_OUTPUT_FLAG_COUNT]; final int[] outProbabilityInfo = new int[FORMAT_WORD_PROPERTY_OUTPUT_PROBABILITY_INFO_COUNT]; - final ArrayList outBigramTargets = CollectionUtils.newArrayList(); - final ArrayList outBigramProbabilityInfo = CollectionUtils.newArrayList(); - final ArrayList outShortcutTargets = CollectionUtils.newArrayList(); - final ArrayList outShortcutProbabilities = CollectionUtils.newArrayList(); + final ArrayList outBigramTargets = new ArrayList<>(); + final ArrayList outBigramProbabilityInfo = new ArrayList<>(); + final ArrayList outShortcutTargets = new ArrayList<>(); + final ArrayList outShortcutProbabilities = new ArrayList<>(); getWordPropertyNative(mNativeDict, codePoints, outCodePoints, outFlags, outProbabilityInfo, outBigramTargets, outBigramProbabilityInfo, outShortcutTargets, outShortcutProbabilities); diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java index 72757e086..10b1f1b77 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java @@ -29,7 +29,6 @@ import android.util.Log; import com.android.inputmethod.dictionarypack.DictionaryPackConstants; import com.android.inputmethod.dictionarypack.MD5Calculator; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.DictionaryInfoUtils; import com.android.inputmethod.latin.utils.DictionaryInfoUtils.DictionaryInfo; import com.android.inputmethod.latin.utils.FileTransforms; @@ -44,8 +43,8 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.util.Arrays; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Locale; @@ -165,7 +164,7 @@ public final class BinaryDictionaryFileDumper { if (cursor.getCount() <= 0 || !cursor.moveToFirst()) { return Collections.emptyList(); } - final ArrayList list = CollectionUtils.newArrayList(); + final ArrayList list = new ArrayList<>(); do { final String wordListId = cursor.getString(0); final String wordListLocale = cursor.getString(1); diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java index 4c49cb31c..867c18686 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java @@ -24,7 +24,6 @@ import android.util.Log; import com.android.inputmethod.latin.makedict.DictionaryHeader; import com.android.inputmethod.latin.makedict.UnsupportedFormatException; import com.android.inputmethod.latin.utils.BinaryDictionaryUtils; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.DictionaryInfoUtils; import com.android.inputmethod.latin.utils.LocaleUtils; @@ -160,7 +159,7 @@ final public class BinaryDictionaryGetter { public static File[] getCachedWordLists(final String locale, final Context context) { final File[] directoryList = DictionaryInfoUtils.getCachedDirectoryList(context); if (null == directoryList) return EMPTY_FILE_ARRAY; - final HashMap cacheFiles = CollectionUtils.newHashMap(); + final HashMap cacheFiles = new HashMap<>(); for (File directory : directoryList) { if (!directory.isDirectory()) continue; final String dirLocale = @@ -273,7 +272,7 @@ final public class BinaryDictionaryGetter { final DictPackSettings dictPackSettings = new DictPackSettings(context); boolean foundMainDict = false; - final ArrayList fileList = CollectionUtils.newArrayList(); + final ArrayList fileList = new ArrayList<>(); // cachedWordLists may not be null, see doc for getCachedDictionaryList for (final File f : cachedWordLists) { final String wordListId = DictionaryInfoUtils.getWordListIdFromFileName(f.getName()); diff --git a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java index 538bfc06f..dd5b376a1 100644 --- a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java @@ -31,7 +31,6 @@ import android.util.Log; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.personalization.AccountUtils; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.ExecutorUtils; import com.android.inputmethod.latin.utils.StringUtils; @@ -180,7 +179,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { private void addWordsLocked(final Cursor cursor) { int count = 0; - final ArrayList names = CollectionUtils.newArrayList(); + final ArrayList names = new ArrayList<>(); while (!cursor.isAfterLast() && count < MAX_CONTACT_COUNT) { String name = cursor.getString(INDEX_NAME); if (isValidName(name)) { @@ -298,7 +297,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { if (null == cursor) { return false; } - final ArrayList names = CollectionUtils.newArrayList(); + final ArrayList names = new ArrayList<>(); try { if (cursor.moveToFirst()) { while (!cursor.isAfterLast()) { diff --git a/java/src/com/android/inputmethod/latin/DictionaryCollection.java b/java/src/com/android/inputmethod/latin/DictionaryCollection.java index e6e4e0938..53be28139 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryCollection.java +++ b/java/src/com/android/inputmethod/latin/DictionaryCollection.java @@ -20,7 +20,6 @@ import android.util.Log; import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; -import com.android.inputmethod.latin.utils.CollectionUtils; import java.util.ArrayList; import java.util.Collection; @@ -36,22 +35,22 @@ public final class DictionaryCollection extends Dictionary { public DictionaryCollection(final String dictType) { super(dictType); - mDictionaries = CollectionUtils.newCopyOnWriteArrayList(); + mDictionaries = new CopyOnWriteArrayList<>(); } public DictionaryCollection(final String dictType, final Dictionary... dictionaries) { super(dictType); if (null == dictionaries) { - mDictionaries = CollectionUtils.newCopyOnWriteArrayList(); + mDictionaries = new CopyOnWriteArrayList<>(); } else { - mDictionaries = CollectionUtils.newCopyOnWriteArrayList(dictionaries); + mDictionaries = new CopyOnWriteArrayList<>(dictionaries); mDictionaries.removeAll(Collections.singleton(null)); } } public DictionaryCollection(final String dictType, final Collection dictionaries) { super(dictType); - mDictionaries = CollectionUtils.newCopyOnWriteArrayList(dictionaries); + mDictionaries = new CopyOnWriteArrayList<>(dictionaries); mDictionaries.removeAll(Collections.singleton(null)); } @@ -67,7 +66,7 @@ public final class DictionaryCollection extends Dictionary { ArrayList suggestions = dictionaries.get(0).getSuggestions(composer, prevWordsInfo, proximityInfo, blockOffensiveWords, additionalFeaturesOptions, sessionId, inOutLanguageWeight); - if (null == suggestions) suggestions = CollectionUtils.newArrayList(); + if (null == suggestions) suggestions = new ArrayList<>(); final int length = dictionaries.size(); for (int i = 1; i < length; ++ i) { final ArrayList sugg = dictionaries.get(i).getSuggestions(composer, diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java index 212363895..80f0cea5e 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java @@ -29,7 +29,6 @@ import com.android.inputmethod.latin.personalization.PersonalizationDataChunk; import com.android.inputmethod.latin.personalization.PersonalizationDictionary; import com.android.inputmethod.latin.personalization.UserHistoryDictionary; import com.android.inputmethod.latin.settings.SpacingAndPunctuations; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.DistracterFilter; import com.android.inputmethod.latin.utils.ExecutorUtils; import com.android.inputmethod.latin.utils.LanguageModelParam; @@ -41,10 +40,10 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -75,7 +74,7 @@ public class DictionaryFacilitator { }; private static final Map> - DICT_TYPE_TO_CLASS = CollectionUtils.newHashMap(); + DICT_TYPE_TO_CLASS = new HashMap<>(); static { DICT_TYPE_TO_CLASS.put(Dictionary.TYPE_USER_HISTORY, UserHistoryDictionary.class); @@ -100,7 +99,7 @@ public class DictionaryFacilitator { public final Locale mLocale; private Dictionary mMainDict; public final ConcurrentHashMap mSubDictMap = - CollectionUtils.newConcurrentHashMap(); + new ConcurrentHashMap<>(); public Dictionaries() { mLocale = null; @@ -212,7 +211,7 @@ public class DictionaryFacilitator { // We always try to have the main dictionary. Other dictionaries can be unused. final boolean reloadMainDictionary = localeHasBeenChanged || forceReloadMainDictionary; // TODO: Make subDictTypesToUse configurable by resource or a static final list. - final Set subDictTypesToUse = CollectionUtils.newHashSet(); + final HashSet subDictTypesToUse = new HashSet<>(); if (useContactsDict) { subDictTypesToUse.add(Dictionary.TYPE_CONTACTS); } @@ -231,7 +230,7 @@ public class DictionaryFacilitator { newMainDict = mDictionaries.getDict(Dictionary.TYPE_MAIN); } - final Map subDicts = CollectionUtils.newHashMap(); + final Map subDicts = new HashMap<>(); for (final String dictType : SUB_DICT_TYPES) { if (!subDictTypesToUse.contains(dictType)) { // This dictionary will not be used. @@ -304,7 +303,7 @@ public class DictionaryFacilitator { final ArrayList dictionaryTypes, final HashMap dictionaryFiles, final Map> additionalDictAttributes) { Dictionary mainDictionary = null; - final Map subDicts = CollectionUtils.newHashMap(); + final Map subDicts = new HashMap<>(); for (final String dictType : dictionaryTypes) { if (dictType.equals(Dictionary.TYPE_MAIN)) { diff --git a/java/src/com/android/inputmethod/latin/DictionaryFactory.java b/java/src/com/android/inputmethod/latin/DictionaryFactory.java index e09c309ea..59de4f82a 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFactory.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFactory.java @@ -23,7 +23,6 @@ import android.content.res.Resources; import android.util.Log; import com.android.inputmethod.annotations.UsedForTesting; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.DictionaryInfoUtils; import java.io.File; @@ -55,7 +54,7 @@ public final class DictionaryFactory { createReadOnlyBinaryDictionary(context, locale)); } - final LinkedList dictList = CollectionUtils.newLinkedList(); + final LinkedList dictList = new LinkedList<>(); final ArrayList assetFileList = BinaryDictionaryGetter.getDictionaryFiles(locale, context); if (null != assetFileList) { diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java index 2cbce045d..b92f04252 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java @@ -53,7 +53,6 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { private static final String TAG = ExpandableBinaryDictionary.class.getSimpleName(); /** Whether to print debug output to log */ - private static boolean DEBUG = false; private static final boolean DBG_STRESS_TEST = false; private static final int TIMEOUT_FOR_READ_OPS_IN_MILLISECONDS = 100; @@ -192,7 +191,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { } protected Map getHeaderAttributeMap() { - HashMap attributeMap = new HashMap(); + HashMap attributeMap = new HashMap<>(); if (mAdditionalAttributeMap != null) { attributeMap.putAll(mAdditionalAttributeMap); } diff --git a/java/src/com/android/inputmethod/latin/InputAttributes.java b/java/src/com/android/inputmethod/latin/InputAttributes.java index df4948322..e778a14f6 100644 --- a/java/src/com/android/inputmethod/latin/InputAttributes.java +++ b/java/src/com/android/inputmethod/latin/InputAttributes.java @@ -20,7 +20,6 @@ import android.text.InputType; import android.util.Log; import android.view.inputmethod.EditorInfo; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.InputTypeUtils; import com.android.inputmethod.latin.utils.StringUtils; @@ -214,7 +213,7 @@ public final class InputAttributes { } private static String toFlagsString(final int flags) { - final ArrayList flagsArray = CollectionUtils.newArrayList(); + final ArrayList flagsArray = new ArrayList<>(); if (0 != (flags & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS)) flagsArray.add("TYPE_TEXT_FLAG_NO_SUGGESTIONS"); if (0 != (flags & InputType.TYPE_TEXT_FLAG_MULTI_LINE)) diff --git a/java/src/com/android/inputmethod/latin/LastComposedWord.java b/java/src/com/android/inputmethod/latin/LastComposedWord.java index 9caec3e01..8cbf8379b 100644 --- a/java/src/com/android/inputmethod/latin/LastComposedWord.java +++ b/java/src/com/android/inputmethod/latin/LastComposedWord.java @@ -69,7 +69,7 @@ public final class LastComposedWord { mInputPointers.copy(inputPointers); } mTypedWord = typedWord; - mEvents = new ArrayList(events); + mEvents = new ArrayList<>(events); mCommittedWord = committedWord; mSeparatorString = separatorString; mActive = true; diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 34d5f714c..1e1d10931 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -81,7 +81,6 @@ import com.android.inputmethod.latin.suggestions.SuggestionStripView; import com.android.inputmethod.latin.suggestions.SuggestionStripViewAccessor; import com.android.inputmethod.latin.utils.ApplicationUtils; import com.android.inputmethod.latin.utils.CapsModeUtils; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.CoordinateUtils; import com.android.inputmethod.latin.utils.DialogUtils; import com.android.inputmethod.latin.utils.DistracterFilterUsingSuggestion; @@ -130,8 +129,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen this /* SuggestionStripViewAccessor */, mDictionaryFacilitator); // We expect to have only one decoder in almost all cases, hence the default capacity of 1. // If it turns out we need several, it will get grown seamlessly. - final SparseArray mHardwareEventDecoders - = new SparseArray(1); + final SparseArray mHardwareEventDecoders = new SparseArray<>(1); private View mExtractArea; private View mKeyPreviewBackingView; diff --git a/java/src/com/android/inputmethod/latin/PunctuationSuggestions.java b/java/src/com/android/inputmethod/latin/PunctuationSuggestions.java index 4911bcdf6..0fba37c8a 100644 --- a/java/src/com/android/inputmethod/latin/PunctuationSuggestions.java +++ b/java/src/com/android/inputmethod/latin/PunctuationSuggestions.java @@ -17,8 +17,6 @@ package com.android.inputmethod.latin; import com.android.inputmethod.keyboard.internal.KeySpecParser; -import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.StringUtils; import java.util.ArrayList; @@ -49,7 +47,7 @@ public final class PunctuationSuggestions extends SuggestedWords { */ public static PunctuationSuggestions newPunctuationSuggestions( final String[] punctuationSpecs) { - final ArrayList puncuationsList = CollectionUtils.newArrayList(); + final ArrayList puncuationsList = new ArrayList<>(); for (final String puncSpec : punctuationSpecs) { puncuationsList.add(newHardCodedWordInfo(puncSpec)); } diff --git a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java index 64cc562c8..cbdc4b9eb 100644 --- a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java +++ b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java @@ -31,7 +31,6 @@ import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; import com.android.inputmethod.latin.settings.Settings; import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; import java.util.Collections; @@ -53,9 +52,9 @@ public final class RichInputMethodManager { private InputMethodManagerCompatWrapper mImmWrapper; private InputMethodInfoCache mInputMethodInfoCache; final HashMap> - mSubtypeListCacheWithImplicitlySelectedSubtypes = CollectionUtils.newHashMap(); + mSubtypeListCacheWithImplicitlySelectedSubtypes = new HashMap<>(); final HashMap> - mSubtypeListCacheWithoutImplicitlySelectedSubtypes = CollectionUtils.newHashMap(); + mSubtypeListCacheWithoutImplicitlySelectedSubtypes = new HashMap<>(); private static final int INDEX_NOT_FOUND = -1; diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index c8a2fb2f9..a3d09565c 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -255,8 +255,7 @@ public final class SubtypeSwitcher { public boolean isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes() { final Locale systemLocale = mResources.getConfiguration().locale; - final Set enabledSubtypesOfEnabledImes = - new HashSet(); + final Set enabledSubtypesOfEnabledImes = new HashSet<>(); final InputMethodManager inputMethodManager = mRichImm.getInputMethodManager(); final List enabledInputMethodInfoList = inputMethodManager.getEnabledInputMethodList(); diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index daa7f4b47..eafe597f2 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -24,7 +24,6 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.utils.AutoCorrectionUtils; import com.android.inputmethod.latin.utils.BinaryDictionaryUtils; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.StringUtils; import com.android.inputmethod.latin.utils.SuggestionResults; @@ -106,7 +105,7 @@ public final class Suggest { final ArrayList rawSuggestions; if (ProductionFlag.INCLUDE_RAW_SUGGESTIONS) { - rawSuggestions = CollectionUtils.newArrayList(); + rawSuggestions = new ArrayList<>(); } else { rawSuggestions = null; } @@ -175,7 +174,7 @@ public final class Suggest { } final ArrayList suggestionsContainer = - CollectionUtils.newArrayList(suggestionResults); + new ArrayList<>(suggestionResults); final int suggestionsCount = suggestionsContainer.size(); if (isFirstCharCapitalized || isAllUpperCase || 0 != trailingSingleQuotesCount) { for (int i = 0; i < suggestionsCount; ++i) { @@ -227,7 +226,7 @@ public final class Suggest { final OnGetSuggestedWordsCallback callback) { final ArrayList rawSuggestions; if (ProductionFlag.INCLUDE_RAW_SUGGESTIONS) { - rawSuggestions = CollectionUtils.newArrayList(); + rawSuggestions = new ArrayList<>(); } else { rawSuggestions = null; } @@ -239,7 +238,7 @@ public final class Suggest { } final ArrayList suggestionsContainer = - CollectionUtils.newArrayList(suggestionResults); + new ArrayList<>(suggestionResults); final int suggestionsCount = suggestionsContainer.size(); final boolean isFirstCharCapitalized = wordComposer.wasShiftedNoLock(); final boolean isAllUpperCase = wordComposer.isAllUpperCase(); @@ -282,8 +281,7 @@ public final class Suggest { final SuggestedWordInfo typedWordInfo = suggestions.get(0); typedWordInfo.setDebugString("+"); final int suggestionsSize = suggestions.size(); - final ArrayList suggestionsList = - CollectionUtils.newArrayList(suggestionsSize); + final ArrayList suggestionsList = new ArrayList<>(suggestionsSize); suggestionsList.add(typedWordInfo); // 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. diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index dc2c9fd0e..758afd80a 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -19,7 +19,6 @@ package com.android.inputmethod.latin; import android.text.TextUtils; import android.view.inputmethod.CompletionInfo; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.StringUtils; import java.util.ArrayList; @@ -34,8 +33,7 @@ public class SuggestedWords { // The maximum number of suggestions available. public static final int MAX_SUGGESTIONS = 18; - private static final ArrayList EMPTY_WORD_INFO_LIST = - CollectionUtils.newArrayList(0); + private static final ArrayList EMPTY_WORD_INFO_LIST = new ArrayList<>(0); public static final SuggestedWords EMPTY = new SuggestedWords( EMPTY_WORD_INFO_LIST, null /* rawSuggestions */, false, false, false, false); @@ -165,7 +163,7 @@ public class SuggestedWords { public static ArrayList getFromApplicationSpecifiedCompletions( final CompletionInfo[] infos) { - final ArrayList result = CollectionUtils.newArrayList(); + final ArrayList result = new ArrayList<>(); for (final CompletionInfo info : infos) { if (null == info || null == info.getText()) { continue; @@ -179,8 +177,8 @@ public class SuggestedWords { // and replace it with what the user currently typed. public static ArrayList getTypedWordAndPreviousSuggestions( final String typedWord, final SuggestedWords previousSuggestions) { - final ArrayList suggestionsList = CollectionUtils.newArrayList(); - final HashSet alreadySeen = CollectionUtils.newHashSet(); + final ArrayList suggestionsList = new ArrayList<>(); + final HashSet alreadySeen = new HashSet<>(); suggestionsList.add(new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_TYPED, Dictionary.DICTIONARY_USER_TYPED, SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */, @@ -337,7 +335,7 @@ public class SuggestedWords { // SuggestedWords is an immutable object, as much as possible. We must not just remove // words from the member ArrayList as some other parties may expect the object to never change. public SuggestedWords getSuggestedWordsExcludingTypedWord() { - final ArrayList newSuggestions = CollectionUtils.newArrayList(); + final ArrayList newSuggestions = new ArrayList<>(); String typedWord = null; for (int i = 0; i < mSuggestedWordInfoList.size(); ++i) { final SuggestedWordInfo info = mSuggestedWordInfoList.get(i); @@ -361,7 +359,7 @@ public class SuggestedWords { // we should only suggest replacements for this last word. // TODO: make this work with languages without spaces. public SuggestedWords getSuggestedWordsForLastWordOfPhraseGesture() { - final ArrayList newSuggestions = CollectionUtils.newArrayList(); + final ArrayList newSuggestions = new ArrayList<>(); for (int i = 0; i < mSuggestedWordInfoList.size(); ++i) { final SuggestedWordInfo info = mSuggestedWordInfoList.get(i); final int indexOfLastSpace = info.mWord.lastIndexOf(Constants.CODE_SPACE) + 1; diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index c53a8fda4..864942d04 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -18,7 +18,6 @@ package com.android.inputmethod.latin; import com.android.inputmethod.event.CombinerChain; import com.android.inputmethod.event.Event; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.CoordinateUtils; import com.android.inputmethod.latin.utils.StringUtils; @@ -79,7 +78,7 @@ public final class WordComposer { public WordComposer() { mCombinerChain = new CombinerChain(""); - mEvents = CollectionUtils.newArrayList(); + mEvents = new ArrayList<>(); mAutoCorrection = null; mIsResumed = false; mIsBatchMode = false; diff --git a/java/src/com/android/inputmethod/latin/debug/ExternalDictionaryGetterForDebug.java b/java/src/com/android/inputmethod/latin/debug/ExternalDictionaryGetterForDebug.java index 139e73aa4..7071d8689 100644 --- a/java/src/com/android/inputmethod/latin/debug/ExternalDictionaryGetterForDebug.java +++ b/java/src/com/android/inputmethod/latin/debug/ExternalDictionaryGetterForDebug.java @@ -27,7 +27,6 @@ import com.android.inputmethod.latin.BinaryDictionaryFileDumper; import com.android.inputmethod.latin.BinaryDictionaryGetter; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.makedict.DictionaryHeader; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.DialogUtils; import com.android.inputmethod.latin.utils.DictionaryInfoUtils; import com.android.inputmethod.latin.utils.LocaleUtils; @@ -50,7 +49,7 @@ public class ExternalDictionaryGetterForDebug { private static String[] findDictionariesInTheDownloadedFolder() { final File[] files = new File(SOURCE_FOLDER).listFiles(); - final ArrayList eligibleList = CollectionUtils.newArrayList(); + final ArrayList eligibleList = new ArrayList<>(); for (File f : files) { final DictionaryHeader header = DictionaryInfoUtils.getDictionaryFileHeaderOrNull(f); if (null == header) continue; diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index 237b43bfb..23d65f181 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -49,7 +49,6 @@ import com.android.inputmethod.latin.settings.SettingsValues; import com.android.inputmethod.latin.settings.SpacingAndPunctuations; import com.android.inputmethod.latin.suggestions.SuggestionStripViewAccessor; import com.android.inputmethod.latin.utils.AsyncResultHolder; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.InputTypeUtils; import com.android.inputmethod.latin.utils.LatinImeLoggerUtils; import com.android.inputmethod.latin.utils.RecapitalizeStatus; @@ -89,7 +88,7 @@ public final class InputLogic { private int mDeleteCount; private long mLastKeyTime; - public final TreeSet mCurrentlyPressedHardwareKeys = CollectionUtils.newTreeSet(); + public final TreeSet mCurrentlyPressedHardwareKeys = new TreeSet<>(); // Keeps track of most recently inserted text (multi-character key) for reverting private String mEnteredText; @@ -1270,7 +1269,7 @@ public final class InputLogic { return; } - final AsyncResultHolder holder = new AsyncResultHolder(); + final AsyncResultHolder holder = new AsyncResultHolder<>(); mInputLogicHandler.getSuggestedWords(Suggest.SESSION_TYPING, SuggestedWords.NOT_A_SEQUENCE_NUMBER, new OnGetSuggestedWordsCallback() { @Override @@ -1350,7 +1349,7 @@ public final class InputLogic { // we just do not resume because it's safer. final int numberOfCharsInWordBeforeCursor = range.getNumberOfCharsInWordBeforeCursor(); if (numberOfCharsInWordBeforeCursor > expectedCursorPosition) return; - final ArrayList suggestions = CollectionUtils.newArrayList(); + final ArrayList suggestions = new ArrayList<>(); final String typedWord = range.mWord.toString(); if (includeResumedWordInSuggestions) { suggestions.add(new SuggestedWordInfo(typedWord, @@ -1473,7 +1472,7 @@ public final class InputLogic { committedWord.length(), Object.class); final int lastCharIndex = textToCommit.length() - 1; // We will collect all suggestions in the following array. - final ArrayList suggestions = CollectionUtils.newArrayList(); + final ArrayList suggestions = new ArrayList<>(); // First, add the committed word to the list of suggestions. suggestions.add(committedWordString); for (final Object span : spans) { diff --git a/java/src/com/android/inputmethod/latin/makedict/WordProperty.java b/java/src/com/android/inputmethod/latin/makedict/WordProperty.java index ed832510c..31cb59756 100644 --- a/java/src/com/android/inputmethod/latin/makedict/WordProperty.java +++ b/java/src/com/android/inputmethod/latin/makedict/WordProperty.java @@ -18,7 +18,6 @@ package com.android.inputmethod.latin.makedict; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.BinaryDictionary; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.CombinedFormatUtils; import com.android.inputmethod.latin.utils.StringUtils; @@ -78,8 +77,8 @@ public final class WordProperty implements Comparable { final ArrayList shortcutProbabilities) { mWord = StringUtils.getStringFromNullTerminatedCodePointArray(codePoints); mProbabilityInfo = createProbabilityInfoFromArray(probabilityInfo); - mShortcutTargets = CollectionUtils.newArrayList(); - mBigrams = CollectionUtils.newArrayList(); + mShortcutTargets = new ArrayList<>(); + mBigrams = new ArrayList<>(); mIsBeginningOfSentence = false; mIsNotAWord = isNotAWord; mIsBlacklistEntry = isBlacklisted; diff --git a/java/src/com/android/inputmethod/latin/personalization/AccountUtils.java b/java/src/com/android/inputmethod/latin/personalization/AccountUtils.java index a446672cb..ab3ef964e 100644 --- a/java/src/com/android/inputmethod/latin/personalization/AccountUtils.java +++ b/java/src/com/android/inputmethod/latin/personalization/AccountUtils.java @@ -35,7 +35,7 @@ public class AccountUtils { } public static List getDeviceAccountsEmailAddresses(final Context context) { - final ArrayList retval = new ArrayList(); + final ArrayList retval = new ArrayList<>(); for (final Account account : getAccounts(context)) { final String name = account.name; if (Patterns.EMAIL_ADDRESS.matcher(name).matches()) { @@ -54,7 +54,7 @@ public class AccountUtils { */ public static List getDeviceAccountsWithDomain( final Context context, final String domain) { - final ArrayList retval = new ArrayList(); + final ArrayList retval = new ArrayList<>(); final String atDomain = "@" + domain.toLowerCase(Locale.ROOT); for (final Account account : getAccounts(context)) { if (account.name.toLowerCase(Locale.ROOT).endsWith(atDomain)) { diff --git a/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java b/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java index 06bdba054..be658ceff 100644 --- a/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java +++ b/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java @@ -31,7 +31,6 @@ import java.util.Map; * model. */ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableBinaryDictionary { - private static final String TAG = DecayingExpandableBinaryDictionaryBase.class.getSimpleName(); private static final boolean DBG_DUMP_ON_CLOSE = false; /** Any pair being typed or picked */ diff --git a/java/src/com/android/inputmethod/latin/personalization/PersonalizationHelper.java b/java/src/com/android/inputmethod/latin/personalization/PersonalizationHelper.java index 6ef505e76..aac40940b 100644 --- a/java/src/com/android/inputmethod/latin/personalization/PersonalizationHelper.java +++ b/java/src/com/android/inputmethod/latin/personalization/PersonalizationHelper.java @@ -16,12 +16,11 @@ package com.android.inputmethod.latin.personalization; -import com.android.inputmethod.latin.utils.CollectionUtils; -import com.android.inputmethod.latin.utils.FileUtils; - import android.content.Context; import android.util.Log; +import com.android.inputmethod.latin.utils.FileUtils; + import java.io.File; import java.io.FilenameFilter; import java.lang.ref.SoftReference; @@ -33,9 +32,9 @@ public class PersonalizationHelper { private static final String TAG = PersonalizationHelper.class.getSimpleName(); private static final boolean DEBUG = false; private static final ConcurrentHashMap> - sLangUserHistoryDictCache = CollectionUtils.newConcurrentHashMap(); + sLangUserHistoryDictCache = new ConcurrentHashMap<>(); private static final ConcurrentHashMap> - sLangPersonalizationDictCache = CollectionUtils.newConcurrentHashMap(); + sLangPersonalizationDictCache = new ConcurrentHashMap<>(); public static UserHistoryDictionary getUserHistoryDictionary( final Context context, final Locale locale) { @@ -54,8 +53,7 @@ public class PersonalizationHelper { } } final UserHistoryDictionary dict = new UserHistoryDictionary(context, locale); - sLangUserHistoryDictCache.put(localeStr, - new SoftReference(dict)); + sLangUserHistoryDictCache.put(localeStr, new SoftReference<>(dict)); return dict; } } @@ -108,8 +106,7 @@ public class PersonalizationHelper { } } final PersonalizationDictionary dict = new PersonalizationDictionary(context, locale); - sLangPersonalizationDictCache.put( - localeStr, new SoftReference(dict)); + sLangPersonalizationDictCache.put(localeStr, new SoftReference<>(dict)); return dict; } } diff --git a/java/src/com/android/inputmethod/latin/settings/AdditionalSubtypeSettings.java b/java/src/com/android/inputmethod/latin/settings/AdditionalSubtypeSettings.java index 39977e76f..31fa86774 100644 --- a/java/src/com/android/inputmethod/latin/settings/AdditionalSubtypeSettings.java +++ b/java/src/com/android/inputmethod/latin/settings/AdditionalSubtypeSettings.java @@ -47,7 +47,6 @@ import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.RichInputMethodManager; import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.DialogUtils; import com.android.inputmethod.latin.utils.IntentUtils; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; @@ -101,7 +100,7 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment { super(context, android.R.layout.simple_spinner_item); setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - final TreeSet items = CollectionUtils.newTreeSet(); + final TreeSet items = new TreeSet<>(); final InputMethodInfo imi = RichInputMethodManager.getInstance() .getInputMethodInfoOfThisIme(); final int count = imi.getSubtypeCount(); @@ -369,7 +368,6 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment { mSubtype = (InputMethodSubtype)source.readParcelable(null); } - @SuppressWarnings("hiding") public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { @Override @@ -516,8 +514,7 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment { localeString, keyboardLayoutSetName); } - private AlertDialog createDialog( - @SuppressWarnings("unused") final SubtypePreference subtypePref) { + private AlertDialog createDialog(final SubtypePreference subtypePref) { final AlertDialog.Builder builder = new AlertDialog.Builder( DialogUtils.getPlatformDialogThemeContext(getActivity())); builder.setTitle(R.string.custom_input_styles_title) @@ -555,7 +552,7 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment { private InputMethodSubtype[] getSubtypes() { final PreferenceGroup group = getPreferenceScreen(); - final ArrayList subtypes = CollectionUtils.newArrayList(); + final ArrayList subtypes = new ArrayList<>(); final int count = group.getPreferenceCount(); for (int i = 0; i < count; i++) { final Preference pref = group.getPreference(i); diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java index 16fd05877..d97323ba8 100644 --- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java @@ -171,7 +171,7 @@ public final class SettingsValues { ResourceUtils.getFloatFromFraction( res, R.fraction.config_key_preview_dismiss_end_scale)); mDisplayOrientation = res.getConfiguration().orientation; - mAppWorkarounds = new AsyncResultHolder(); + mAppWorkarounds = new AsyncResultHolder<>(); final PackageInfo packageInfo = TargetPackageInfoGetterTask.getCachedPackageInfo( mInputAttributes.mTargetApplicationPackageName); if (null != packageInfo) { diff --git a/java/src/com/android/inputmethod/latin/setup/SetupWizardActivity.java b/java/src/com/android/inputmethod/latin/setup/SetupWizardActivity.java index 5072fabd6..bcac05a6a 100644 --- a/java/src/com/android/inputmethod/latin/setup/SetupWizardActivity.java +++ b/java/src/com/android/inputmethod/latin/setup/SetupWizardActivity.java @@ -37,7 +37,6 @@ import com.android.inputmethod.compat.TextViewCompatUtils; import com.android.inputmethod.compat.ViewCompatUtils; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.settings.SettingsActivity; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper; import java.util.ArrayList; @@ -482,7 +481,7 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL static final class SetupStepGroup { private final SetupStepIndicatorView mIndicatorView; - private final ArrayList mGroup = CollectionUtils.newArrayList(); + private final ArrayList mGroup = new ArrayList<>(); public SetupStepGroup(final SetupStepIndicatorView indicatorView) { mIndicatorView = indicatorView; diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java index 65ebcf5f1..8d495646d 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java @@ -27,7 +27,6 @@ import android.view.inputmethod.InputMethodSubtype; import android.view.textservice.SuggestionsInfo; import com.android.inputmethod.keyboard.KeyboardLayoutSet; -import com.android.inputmethod.latin.BinaryDictionary; import com.android.inputmethod.latin.ContactsBinaryDictionary; import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.DictionaryCollection; @@ -77,7 +76,7 @@ public final class AndroidSpellCheckerService extends SpellCheckerService private final Object mUseContactsLock = new Object(); private final HashSet> mDictionaryCollectionsList = - CollectionUtils.newHashSet(); + new HashSet<>(); public static final int SCRIPT_LATIN = 0; public static final int SCRIPT_CYRILLIC = 1; @@ -94,7 +93,7 @@ public final class AndroidSpellCheckerService extends SpellCheckerService // proximity to pass to the dictionary descent algorithm. // IMPORTANT: this only contains languages - do not write countries in there. // Only the language is searched from the map. - mLanguageToScript = CollectionUtils.newTreeMap(); + mLanguageToScript = new TreeMap<>(); mLanguageToScript.put("cs", SCRIPT_LATIN); mLanguageToScript.put("da", SCRIPT_LATIN); mLanguageToScript.put("de", SCRIPT_LATIN); @@ -255,7 +254,7 @@ public final class AndroidSpellCheckerService extends SpellCheckerService mOriginalText = originalText; mRecommendedThreshold = recommendedThreshold; mMaxLength = maxLength; - mSuggestions = CollectionUtils.newArrayList(maxLength + 1); + mSuggestions = new ArrayList<>(maxLength + 1); mScores = new int[mMaxLength]; } @@ -441,8 +440,7 @@ public final class AndroidSpellCheckerService extends SpellCheckerService } } dictionaryCollection.addDictionary(mContactsDictionary); - mDictionaryCollectionsList.add( - new WeakReference(dictionaryCollection)); + mDictionaryCollectionsList.add(new WeakReference<>(dictionaryCollection)); } return new DictAndKeyboard(dictionaryCollection, keyboardLayoutSet); } diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerSession.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerSession.java index e951f5a89..cc80e6f21 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerSession.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerSession.java @@ -24,7 +24,6 @@ import android.view.textservice.SuggestionsInfo; import android.view.textservice.TextInfo; import com.android.inputmethod.latin.PrevWordsInfo; -import com.android.inputmethod.latin.utils.CollectionUtils; import java.util.ArrayList; @@ -44,10 +43,9 @@ public final class AndroidSpellCheckerSession extends AndroidWordLevelSpellCheck return null; } final int N = ssi.getSuggestionsCount(); - final ArrayList additionalOffsets = CollectionUtils.newArrayList(); - final ArrayList additionalLengths = CollectionUtils.newArrayList(); - final ArrayList additionalSuggestionsInfos = - CollectionUtils.newArrayList(); + final ArrayList additionalOffsets = new ArrayList<>(); + final ArrayList additionalLengths = new ArrayList<>(); + final ArrayList additionalSuggestionsInfos = new ArrayList<>(); String currentWord = null; for (int i = 0; i < N; ++i) { final SuggestionsInfo si = ssi.getSuggestionsInfoAt(i); diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java index cf26000d5..d7953e6e7 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java @@ -28,7 +28,6 @@ import android.view.textservice.SuggestionsInfo; import android.view.textservice.TextInfo; import com.android.inputmethod.compat.SuggestionsInfoCompatUtils; -import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.PrevWordsInfo; @@ -69,7 +68,7 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session { private static final char CHAR_DELIMITER = '\uFFFC'; private static final int MAX_CACHE_SIZE = 50; private final LruCache mUnigramSuggestionsInfoCache = - new LruCache(MAX_CACHE_SIZE); + new LruCache<>(MAX_CACHE_SIZE); // TODO: Support n-gram input private static String generateKey(final String query, final PrevWordsInfo prevWordsInfo) { diff --git a/java/src/com/android/inputmethod/latin/spellcheck/DictAndKeyboard.java b/java/src/com/android/inputmethod/latin/spellcheck/DictAndKeyboard.java index 1ffe50681..b33739fc1 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/DictAndKeyboard.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/DictAndKeyboard.java @@ -16,11 +16,11 @@ package com.android.inputmethod.latin.spellcheck; -import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.keyboard.KeyboardLayoutSet; import com.android.inputmethod.keyboard.ProximityInfo; +import com.android.inputmethod.latin.Dictionary; /** * A container for a Dictionary and a Keyboard. @@ -28,19 +28,15 @@ import com.android.inputmethod.keyboard.ProximityInfo; public final class DictAndKeyboard { public final Dictionary mDictionary; public final Keyboard mKeyboard; - private final Keyboard mManualShiftedKeyboard; public DictAndKeyboard( final Dictionary dictionary, final KeyboardLayoutSet keyboardLayoutSet) { mDictionary = dictionary; if (keyboardLayoutSet == null) { mKeyboard = null; - mManualShiftedKeyboard = null; return; } mKeyboard = keyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET); - mManualShiftedKeyboard = - keyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED); } public ProximityInfo getProximityInfo() { diff --git a/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java b/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java index ba2e0c309..1331d52d5 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java @@ -23,7 +23,6 @@ import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.PrevWordsInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.WordComposer; -import com.android.inputmethod.latin.utils.CollectionUtils; import java.util.ArrayList; import java.util.Locale; @@ -47,7 +46,7 @@ public final class DictionaryPool extends LinkedBlockingQueue { private final Locale mLocale; private int mSize; private volatile boolean mClosed; - final static ArrayList noSuggestions = CollectionUtils.newArrayList(); + final static ArrayList noSuggestions = new ArrayList<>(); private final static DictAndKeyboard dummyDict = new DictAndKeyboard( new Dictionary(Dictionary.TYPE_MAIN) { // TODO: this dummy dictionary should be a singleton in the Dictionary class. diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java index 619804afa..c75636875 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java @@ -50,7 +50,6 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.settings.Settings; import com.android.inputmethod.latin.suggestions.MoreSuggestions.MoreSuggestionsListener; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.ImportantNoticeUtils; import com.android.inputmethod.research.ResearchLogger; @@ -78,9 +77,9 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick private final MoreSuggestionsView mMoreSuggestionsView; private final MoreSuggestions.Builder mMoreSuggestionsBuilder; - private final ArrayList mWordViews = CollectionUtils.newArrayList(); - private final ArrayList mDebugInfoViews = CollectionUtils.newArrayList(); - private final ArrayList mDividerViews = CollectionUtils.newArrayList(); + private final ArrayList mWordViews = new ArrayList<>(); + private final ArrayList mDebugInfoViews = new ArrayList<>(); + private final ArrayList mDividerViews = new ArrayList<>(); Listener mListener; private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY; diff --git a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryAddWordContents.java b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryAddWordContents.java index 21426d1eb..80d4cc44f 100644 --- a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryAddWordContents.java +++ b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryAddWordContents.java @@ -256,7 +256,7 @@ public class UserDictionaryAddWordContents { // The system locale should be inside. We want it at the 2nd spot. locales.remove(systemLocale); // system locale may not be null locales.remove(""); // Remove the empty string if it's there - final ArrayList localesList = new ArrayList(); + final ArrayList localesList = new ArrayList<>(); // Add the passed locale, then the system locale at the top of the list. Add an // "all languages" entry at the bottom of the list. addLocaleDisplayNameToList(activity, localesList, mLocale); diff --git a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryAddWordFragment.java b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryAddWordFragment.java index 4fc132f68..163443036 100644 --- a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryAddWordFragment.java +++ b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryAddWordFragment.java @@ -134,8 +134,8 @@ public class UserDictionaryAddWordFragment extends Fragment final Spinner localeSpinner = (Spinner)mRootView.findViewById(R.id.user_dictionary_add_locale); - final ArrayAdapter adapter = new ArrayAdapter(getActivity(), - android.R.layout.simple_spinner_item, localesList); + final ArrayAdapter adapter = new ArrayAdapter<>( + getActivity(), android.R.layout.simple_spinner_item, localesList); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); localeSpinner.setAdapter(adapter); localeSpinner.setOnItemSelectedListener(this); diff --git a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java index 97a924d7b..624783a70 100644 --- a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java +++ b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java @@ -56,7 +56,7 @@ public class UserDictionaryList extends PreferenceFragment { final Cursor cursor = activity.getContentResolver().query(UserDictionary.Words.CONTENT_URI, new String[] { UserDictionary.Words.LOCALE }, null, null, null); - final TreeSet localeSet = new TreeSet(); + final TreeSet localeSet = new TreeSet<>(); if (null == cursor) { // The user dictionary service is not present or disabled. Return null. return null; diff --git a/java/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtils.java b/java/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtils.java index 2bb30a2ba..3ca7c7e1c 100644 --- a/java/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtils.java @@ -95,8 +95,7 @@ public final class AdditionalSubtypeUtils { return EMPTY_SUBTYPE_ARRAY; } final String[] prefSubtypeArray = prefSubtypes.split(PREF_SUBTYPE_SEPARATOR); - final ArrayList subtypesList = - CollectionUtils.newArrayList(prefSubtypeArray.length); + final ArrayList subtypesList = new ArrayList<>(prefSubtypeArray.length); for (final String prefSubtype : prefSubtypeArray) { final String elems[] = prefSubtype.split(LOCALE_AND_LAYOUT_SEPARATOR); if (elems.length != LENGTH_WITHOUT_EXTRA_VALUE diff --git a/java/src/com/android/inputmethod/latin/utils/AutoCorrectionUtils.java b/java/src/com/android/inputmethod/latin/utils/AutoCorrectionUtils.java index 22b9b77d2..857d0b0da 100644 --- a/java/src/com/android/inputmethod/latin/utils/AutoCorrectionUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/AutoCorrectionUtils.java @@ -16,12 +16,11 @@ package com.android.inputmethod.latin.utils; -import com.android.inputmethod.latin.BinaryDictionary; +import android.util.Log; + import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; -import android.util.Log; - public final class AutoCorrectionUtils { private static final boolean DBG = LatinImeLogger.sDBG; private static final String TAG = AutoCorrectionUtils.class.getSimpleName(); diff --git a/java/src/com/android/inputmethod/latin/utils/CollectionUtils.java b/java/src/com/android/inputmethod/latin/utils/CollectionUtils.java index bbfa0f091..e3aef29ba 100644 --- a/java/src/com/android/inputmethod/latin/utils/CollectionUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/CollectionUtils.java @@ -16,93 +16,21 @@ package com.android.inputmethod.latin.utils; -import android.util.SparseArray; - -import java.util.ArrayDeque; 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.WeakHashMap; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; public final class CollectionUtils { private CollectionUtils() { // This utility class is not publicly instantiable. } - public static HashMap newHashMap() { - return new HashMap(); - } - - public static WeakHashMap newWeakHashMap() { - return new WeakHashMap(); - } - - public static TreeMap newTreeMap() { - return new TreeMap(); - } - public static Map newSynchronizedTreeMap() { - final TreeMap treeMap = newTreeMap(); + final TreeMap treeMap = new TreeMap<>(); return Collections.synchronizedMap(treeMap); } - public static ConcurrentHashMap newConcurrentHashMap() { - return new ConcurrentHashMap(); - } - - public static HashSet newHashSet() { - return new HashSet(); - } - - public static TreeSet newTreeSet() { - return new TreeSet(); - } - - public static ArrayList newArrayList() { - return new ArrayList(); - } - - public static ArrayList newArrayList(final int initialCapacity) { - return new ArrayList(initialCapacity); - } - - public static ArrayList newArrayList(final Collection collection) { - return new ArrayList(collection); - } - - public static LinkedList newLinkedList() { - return new LinkedList(); - } - - public static CopyOnWriteArrayList newCopyOnWriteArrayList() { - return new CopyOnWriteArrayList(); - } - - public static CopyOnWriteArrayList newCopyOnWriteArrayList( - final Collection collection) { - return new CopyOnWriteArrayList(collection); - } - - public static CopyOnWriteArrayList newCopyOnWriteArrayList(final E[] array) { - return new CopyOnWriteArrayList(array); - } - - public static ArrayDeque newArrayDeque() { - return new ArrayDeque(); - } - - public static SparseArray newSparseArray() { - return new SparseArray(); - } - public static ArrayList arrayAsList(final E[] array, final int start, final int end) { if (array == null) { throw new NullPointerException(); @@ -111,7 +39,7 @@ public final class CollectionUtils { throw new IllegalArgumentException(); } - final ArrayList list = newArrayList(end - start); + final ArrayList list = new ArrayList<>(end - start); for (int i = start; i < end; i++) { list.add(array[i]); } diff --git a/java/src/com/android/inputmethod/latin/utils/CsvUtils.java b/java/src/com/android/inputmethod/latin/utils/CsvUtils.java index b18a1d83b..a21a1373b 100644 --- a/java/src/com/android/inputmethod/latin/utils/CsvUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/CsvUtils.java @@ -209,7 +209,7 @@ public final class CsvUtils { @UsedForTesting public static String[] split(final int splitFlags, final String line) throws CsvParseException { final boolean trimSpaces = (splitFlags & SPLIT_FLAGS_TRIM_SPACES) != 0; - final ArrayList fields = CollectionUtils.newArrayList(); + final ArrayList fields = new ArrayList<>(); final int length = line.length(); int start = 0; do { diff --git a/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java b/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java index 315913e2f..d76ea10c0 100644 --- a/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java @@ -336,7 +336,7 @@ public class DictionaryInfoUtils { public static ArrayList getCurrentDictionaryFileNameAndVersionInfo( final Context context) { - final ArrayList dictList = CollectionUtils.newArrayList(); + final ArrayList dictList = new ArrayList<>(); // Retrieve downloaded dictionaries final File[] directoryList = getCachedDirectoryList(context); diff --git a/java/src/com/android/inputmethod/latin/utils/DistracterFilterUsingSuggestion.java b/java/src/com/android/inputmethod/latin/utils/DistracterFilterUsingSuggestion.java index 92033b76f..251a12678 100644 --- a/java/src/com/android/inputmethod/latin/utils/DistracterFilterUsingSuggestion.java +++ b/java/src/com/android/inputmethod/latin/utils/DistracterFilterUsingSuggestion.java @@ -203,7 +203,7 @@ public class DistracterFilterUsingSuggestion implements DistracterFilter { final String consideredWord = trailingSingleQuotesCount > 0 ? testedWord.substring(0, testedWord.length() - trailingSingleQuotesCount) : testedWord; - final AsyncResultHolder holder = new AsyncResultHolder(); + final AsyncResultHolder holder = new AsyncResultHolder<>(); final OnGetSuggestedWordsCallback callback = new OnGetSuggestedWordsCallback() { @Override public void onGetSuggestedWords(final SuggestedWords suggestedWords) { diff --git a/java/src/com/android/inputmethod/latin/utils/ExecutorUtils.java b/java/src/com/android/inputmethod/latin/utils/ExecutorUtils.java index ed502ed3d..7b678e175 100644 --- a/java/src/com/android/inputmethod/latin/utils/ExecutorUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/ExecutorUtils.java @@ -24,8 +24,9 @@ import java.util.concurrent.ConcurrentHashMap; * Utilities to manage executors. */ public class ExecutorUtils { - private static final ConcurrentHashMap - sExecutorMap = CollectionUtils.newConcurrentHashMap(); + private static final ConcurrentHashMap sExecutorMap = + new ConcurrentHashMap<>(); + /** * Gets the executor for the given dictionary name. */ diff --git a/java/src/com/android/inputmethod/latin/utils/FragmentUtils.java b/java/src/com/android/inputmethod/latin/utils/FragmentUtils.java index ee2b97b2a..149fbb31a 100644 --- a/java/src/com/android/inputmethod/latin/utils/FragmentUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/FragmentUtils.java @@ -31,7 +31,7 @@ import com.android.inputmethod.research.FeedbackFragment; import java.util.HashSet; public class FragmentUtils { - private static final HashSet sLatinImeFragments = new HashSet(); + private static final HashSet sLatinImeFragments = new HashSet<>(); static { sLatinImeFragments.add(DictionarySettingsFragment.class.getName()); sLatinImeFragments.add(AboutPreferences.class.getName()); diff --git a/java/src/com/android/inputmethod/latin/utils/JsonUtils.java b/java/src/com/android/inputmethod/latin/utils/JsonUtils.java index 764ef72ce..6dd8d9711 100644 --- a/java/src/com/android/inputmethod/latin/utils/JsonUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/JsonUtils.java @@ -37,7 +37,7 @@ public final class JsonUtils { private static final String EMPTY_STRING = ""; public static List jsonStrToList(final String s) { - final ArrayList list = CollectionUtils.newArrayList(); + final ArrayList list = new ArrayList<>(); final JsonReader reader = new JsonReader(new StringReader(s)); try { reader.beginArray(); diff --git a/java/src/com/android/inputmethod/latin/utils/LanguageModelParam.java b/java/src/com/android/inputmethod/latin/utils/LanguageModelParam.java index 9c759edb6..66ca1124c 100644 --- a/java/src/com/android/inputmethod/latin/utils/LanguageModelParam.java +++ b/java/src/com/android/inputmethod/latin/utils/LanguageModelParam.java @@ -84,8 +84,7 @@ public final class LanguageModelParam { final DictionaryFacilitator dictionaryFacilitator, final SpacingAndPunctuations spacingAndPunctuations, final DistracterFilter distracterFilter) { - final ArrayList languageModelParams = - CollectionUtils.newArrayList(); + final ArrayList languageModelParams = new ArrayList<>(); final int N = tokens.size(); PrevWordsInfo prevWordsInfo = PrevWordsInfo.EMPTY_PREV_WORDS_INFO; for (int i = 0; i < N; ++i) { diff --git a/java/src/com/android/inputmethod/latin/utils/LeakGuardHandlerWrapper.java b/java/src/com/android/inputmethod/latin/utils/LeakGuardHandlerWrapper.java index 8469c87b0..dd6fac671 100644 --- a/java/src/com/android/inputmethod/latin/utils/LeakGuardHandlerWrapper.java +++ b/java/src/com/android/inputmethod/latin/utils/LeakGuardHandlerWrapper.java @@ -33,7 +33,7 @@ public class LeakGuardHandlerWrapper extends Handler { if (ownerInstance == null) { throw new NullPointerException("ownerInstance is null"); } - mOwnerInstanceRef = new WeakReference(ownerInstance); + mOwnerInstanceRef = new WeakReference<>(ownerInstance); } public T getOwnerInstance() { diff --git a/java/src/com/android/inputmethod/latin/utils/LocaleUtils.java b/java/src/com/android/inputmethod/latin/utils/LocaleUtils.java index 0c55484b4..c519a0de6 100644 --- a/java/src/com/android/inputmethod/latin/utils/LocaleUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/LocaleUtils.java @@ -159,7 +159,7 @@ public final class LocaleUtils { return LOCALE_MATCH <= level; } - private static final HashMap sLocaleCache = CollectionUtils.newHashMap(); + private static final HashMap sLocaleCache = new HashMap<>(); /** * Creates a locale from a string specification. diff --git a/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java b/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java index bf38abc95..148f3bce6 100644 --- a/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java +++ b/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java @@ -41,8 +41,8 @@ public class PrioritizedSerialExecutor { private Runnable mActive; public PrioritizedSerialExecutor() { - mTasks = new ConcurrentLinkedQueue(); - mPrioritizedTasks = new ConcurrentLinkedQueue(); + mTasks = new ConcurrentLinkedQueue<>(); + mPrioritizedTasks = new ConcurrentLinkedQueue<>(); mIsShutdown = false; mThreadPoolExecutor = new ThreadPoolExecutor(1 /* corePoolSize */, 1 /* maximumPoolSize */, 0 /* keepAliveTime */, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1)); diff --git a/java/src/com/android/inputmethod/latin/utils/ResourceUtils.java b/java/src/com/android/inputmethod/latin/utils/ResourceUtils.java index 49f4929b4..093c5a6c1 100644 --- a/java/src/com/android/inputmethod/latin/utils/ResourceUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/ResourceUtils.java @@ -41,8 +41,7 @@ public final class ResourceUtils { // This utility class is not publicly instantiable. } - private static final HashMap sDeviceOverrideValueMap = - CollectionUtils.newHashMap(); + private static final HashMap sDeviceOverrideValueMap = new HashMap<>(); private static final String[] BUILD_KEYS_AND_VALUES = { "HARDWARE", Build.HARDWARE, @@ -54,8 +53,8 @@ public final class ResourceUtils { private static final String sBuildKeyValuesDebugString; static { - sBuildKeyValues = CollectionUtils.newHashMap(); - final ArrayList keyValuePairs = CollectionUtils.newArrayList(); + sBuildKeyValues = new HashMap<>(); + final ArrayList keyValuePairs = new ArrayList<>(); final int keyCount = BUILD_KEYS_AND_VALUES.length / 2; for (int i = 0; i < keyCount; i++) { final int index = i * 2; diff --git a/java/src/com/android/inputmethod/latin/utils/StringUtils.java b/java/src/com/android/inputmethod/latin/utils/StringUtils.java index 73ac9a573..4ed0f0a94 100644 --- a/java/src/com/android/inputmethod/latin/utils/StringUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/StringUtils.java @@ -28,7 +28,6 @@ import java.util.Arrays; import java.util.Locale; public final class StringUtils { - private static final String TAG = StringUtils.class.getSimpleName(); public static final int CAPITALIZE_NONE = 0; // No caps, or mixed case public static final int CAPITALIZE_FIRST = 1; // First only public static final int CAPITALIZE_ALL = 2; // All caps @@ -110,7 +109,7 @@ public final class StringUtils { if (!containsInArray(text, elements)) { return extraValues; } - final ArrayList result = CollectionUtils.newArrayList(elements.length - 1); + final ArrayList result = new ArrayList<>(elements.length - 1); for (final String element : elements) { if (!text.equals(element)) { result.add(element); diff --git a/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java b/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java index 938d27122..351d01400 100644 --- a/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java @@ -49,17 +49,14 @@ public final class SubtypeLocaleUtils { private static Resources sResources; private static String[] sPredefinedKeyboardLayoutSet; // Keyboard layout to its display name map. - private static final HashMap sKeyboardLayoutToDisplayNameMap = - CollectionUtils.newHashMap(); + private static final HashMap sKeyboardLayoutToDisplayNameMap = new HashMap<>(); // Keyboard layout to subtype name resource id map. - private static final HashMap sKeyboardLayoutToNameIdsMap = - CollectionUtils.newHashMap(); + private static final HashMap sKeyboardLayoutToNameIdsMap = new HashMap<>(); // Exceptional locale to subtype name resource id map. - private static final HashMap sExceptionalLocaleToNameIdsMap = - CollectionUtils.newHashMap(); + private static final HashMap sExceptionalLocaleToNameIdsMap = new HashMap<>(); // Exceptional locale to subtype name with layout resource id map. private static final HashMap sExceptionalLocaleToWithLayoutNameIdsMap = - CollectionUtils.newHashMap(); + new HashMap<>(); private static final String SUBTYPE_NAME_RESOURCE_PREFIX = "string/subtype_"; private static final String SUBTYPE_NAME_RESOURCE_GENERIC_PREFIX = @@ -71,7 +68,7 @@ public final class SubtypeLocaleUtils { // 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. private static final HashMap sLocaleAndExtraValueToKeyboardLayoutSetMap = - CollectionUtils.newHashMap(); + new HashMap<>(); private SubtypeLocaleUtils() { // Intentional empty constructor for utility class. diff --git a/java/src/com/android/inputmethod/latin/utils/TargetPackageInfoGetterTask.java b/java/src/com/android/inputmethod/latin/utils/TargetPackageInfoGetterTask.java index 42ea3c959..ab2b00e36 100644 --- a/java/src/com/android/inputmethod/latin/utils/TargetPackageInfoGetterTask.java +++ b/java/src/com/android/inputmethod/latin/utils/TargetPackageInfoGetterTask.java @@ -27,8 +27,7 @@ import com.android.inputmethod.compat.AppWorkaroundsUtils; public final class TargetPackageInfoGetterTask extends AsyncTask { private static final int MAX_CACHE_ENTRIES = 64; // arbitrary - private static final LruCache sCache = - new LruCache(MAX_CACHE_ENTRIES); + private static final LruCache sCache = new LruCache<>(MAX_CACHE_ENTRIES); public static PackageInfo getCachedPackageInfo(final String packageName) { if (null == packageName) return null; diff --git a/java/src/com/android/inputmethod/latin/utils/TypefaceUtils.java b/java/src/com/android/inputmethod/latin/utils/TypefaceUtils.java index 087a7f255..fafba79c2 100644 --- a/java/src/com/android/inputmethod/latin/utils/TypefaceUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/TypefaceUtils.java @@ -30,7 +30,7 @@ public final class TypefaceUtils { } // This sparse array caches key label text height in pixel indexed by key label text size. - private static final SparseArray sTextHeightCache = CollectionUtils.newSparseArray(); + private static final SparseArray sTextHeightCache = new SparseArray<>(); // Working variable for the following method. private static final Rect sTextHeightBounds = new Rect(); @@ -50,7 +50,7 @@ public final class TypefaceUtils { } // This sparse array caches key label text width in pixel indexed by key label text size. - private static final SparseArray sTextWidthCache = CollectionUtils.newSparseArray(); + private static final SparseArray sTextWidthCache = new SparseArray<>(); // Working variable for the following method. private static final Rect sTextWidthBounds = new Rect(); diff --git a/java/src/com/android/inputmethod/latin/utils/UserLogRingCharBuffer.java b/java/src/com/android/inputmethod/latin/utils/UserLogRingCharBuffer.java index a75d353c9..cf0ce0d2f 100644 --- a/java/src/com/android/inputmethod/latin/utils/UserLogRingCharBuffer.java +++ b/java/src/com/android/inputmethod/latin/utils/UserLogRingCharBuffer.java @@ -66,7 +66,7 @@ public final class UserLogRingCharBuffer { return; } if (LatinImeLogger.sUsabilityStudy) { - UsabilityStudyLogUtils.getInstance().writeChar(c, x, y); + UsabilityStudyLogUtils.writeChar(c, x, y); } mCharBuf[mEnd] = c; mXBuf[mEnd] = x; diff --git a/java/src/com/android/inputmethod/research/FixedLogBuffer.java b/java/src/com/android/inputmethod/research/FixedLogBuffer.java index 8b64de8ae..210015643 100644 --- a/java/src/com/android/inputmethod/research/FixedLogBuffer.java +++ b/java/src/com/android/inputmethod/research/FixedLogBuffer.java @@ -163,7 +163,7 @@ public class FixedLogBuffer extends LogBuffer { // Allocate space for n*2 logUnits. There will be at least n, one for each word, and // there may be additional for punctuation, between-word commands, etc. This should be // enough that reallocation won't be necessary. - final ArrayList resultList = new ArrayList(n * 2); + final ArrayList resultList = new ArrayList<>(n * 2); for (final LogUnit logUnit : logUnits) { n -= logUnit.getNumWords(); if (n < 0) break; diff --git a/java/src/com/android/inputmethod/research/LogBuffer.java b/java/src/com/android/inputmethod/research/LogBuffer.java index b07b761f0..0d9c357da 100644 --- a/java/src/com/android/inputmethod/research/LogBuffer.java +++ b/java/src/com/android/inputmethod/research/LogBuffer.java @@ -31,7 +31,7 @@ public class LogBuffer { private final LinkedList mLogUnits; public LogBuffer() { - mLogUnits = new LinkedList(); + mLogUnits = new LinkedList<>(); } protected LinkedList getLogUnits() { diff --git a/java/src/com/android/inputmethod/research/LogUnit.java b/java/src/com/android/inputmethod/research/LogUnit.java index 3366df12a..1750751a7 100644 --- a/java/src/com/android/inputmethod/research/LogUnit.java +++ b/java/src/com/android/inputmethod/research/LogUnit.java @@ -93,9 +93,9 @@ public class LogUnit { private SuggestedWords mSuggestedWords; public LogUnit() { - mLogStatementList = new ArrayList(); - mValuesList = new ArrayList(); - mTimeList = new ArrayList(); + mLogStatementList = new ArrayList<>(); + mValuesList = new ArrayList<>(); + mTimeList = new ArrayList<>(); mIsPartOfMegaword = false; mCorrectionType = CORRECTIONTYPE_NO_CORRECTION; mSuggestedWords = null; @@ -311,9 +311,9 @@ public class LogUnit { // Create the LogUnit containing the later logStatements and associated data. final LogUnit newLogUnit = new LogUnit( - new ArrayList(laterLogStatements), - new ArrayList(laterValues), - new ArrayList(laterTimes), + new ArrayList<>(laterLogStatements), + new ArrayList<>(laterValues), + new ArrayList<>(laterTimes), true /* isPartOfMegaword */); newLogUnit.mWords = null; newLogUnit.mMayContainDigit = mMayContainDigit; diff --git a/java/src/com/android/inputmethod/research/MotionEventReader.java b/java/src/com/android/inputmethod/research/MotionEventReader.java index 3388645b7..f6b7352e7 100644 --- a/java/src/com/android/inputmethod/research/MotionEventReader.java +++ b/java/src/com/android/inputmethod/research/MotionEventReader.java @@ -67,11 +67,10 @@ public class MotionEventReader { @UsedForTesting static class ReplayData { - final ArrayList mActions = new ArrayList(); - final ArrayList mPointerPropertiesArrays - = new ArrayList(); - final ArrayList mPointerCoordsArrays = new ArrayList(); - final ArrayList mTimes = new ArrayList(); + final ArrayList mActions = new ArrayList<>(); + final ArrayList mPointerPropertiesArrays = new ArrayList<>(); + final ArrayList mPointerCoordsArrays = new ArrayList<>(); + final ArrayList mTimes = new ArrayList<>(); } /** @@ -228,8 +227,7 @@ public class MotionEventReader { private PointerProperties[] readPointerProperties(final JsonReader jsonReader) throws IOException { - final ArrayList pointerPropertiesArrayList = - new ArrayList(); + final ArrayList pointerPropertiesArrayList = new ArrayList<>(); jsonReader.beginArray(); while (jsonReader.hasNext()) { final PointerProperties pointerProperties = new PointerProperties(); @@ -254,7 +252,7 @@ public class MotionEventReader { jsonReader.beginArray(); while (jsonReader.hasNext()) { // Array of historical data jsonReader.beginObject(); - final ArrayList pointerCoordsArrayList = new ArrayList(); + final ArrayList pointerCoordsArrayList = new ArrayList<>(); while (jsonReader.hasNext()) { // Time/data object final String name = jsonReader.nextName(); if (name.equals("t")) { diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java index 75bd60999..1ccb58c0f 100644 --- a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java +++ b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java @@ -32,7 +32,6 @@ import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.RichInputMethodManager; import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.ResourceUtils; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; @@ -42,11 +41,9 @@ import java.util.Locale; @SmallTest public class KeyboardLayoutSetTestsBase extends AndroidTestCase { // All input method subtypes of LatinIME. - private final ArrayList mAllSubtypesList = CollectionUtils.newArrayList(); - private final ArrayList mAsciiCapableSubtypesList = - CollectionUtils.newArrayList(); - private final ArrayList mAdditionalSubtypesList = - CollectionUtils.newArrayList(); + private final ArrayList mAllSubtypesList = new ArrayList<>(); + private final ArrayList mAsciiCapableSubtypesList = new ArrayList<>(); + private final ArrayList mAdditionalSubtypesList = new ArrayList<>(); private Context mThemeContext; private int mScreenMetrics; diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSetTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSetTests.java index eb906cd9f..72211015f 100644 --- a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSetTests.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSetTests.java @@ -23,7 +23,6 @@ import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.latin.RichInputMethodManager; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; import java.util.ArrayList; @@ -42,7 +41,7 @@ public final class KeyboardTextsSetTests extends AndroidTestCase { RichInputMethodManager.init(getContext()); final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); - final ArrayList allSubtypesList = CollectionUtils.newArrayList(); + final ArrayList allSubtypesList = new ArrayList<>(); final InputMethodInfo imi = richImm.getInputMethodInfoOfThisIme(); final int subtypeCount = imi.getSubtypeCount(); for (int index = 0; index < subtypeCount; index++) { diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java index 514ad1cf0..29b169d80 100644 --- a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java @@ -22,8 +22,6 @@ import android.content.res.Resources; import android.test.InstrumentationTestCase; import android.test.suitebuilder.annotation.MediumTest; -import com.android.inputmethod.latin.utils.CollectionUtils; - import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; @@ -53,7 +51,7 @@ public class MoreKeySpecSplitTests extends InstrumentationTestCase { } private static String[] getAllResourceIdNames(final Class resourceIdClass) { - final ArrayList names = CollectionUtils.newArrayList(); + final ArrayList names = new ArrayList<>(); for (final Field field : resourceIdClass.getFields()) { if (field.getType() == Integer.TYPE) { names.add(field.getName()); diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java index d0fea58b0..56149189f 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java @@ -20,7 +20,6 @@ import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.keyboard.internal.MoreKeySpec; import com.android.inputmethod.latin.Constants; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.StringUtils; import java.util.ArrayList; @@ -34,7 +33,7 @@ import java.util.List; */ public final class ActualKeyboardBuilder extends AbstractKeyboardBuilder { private static ArrayList filterOutSpacer(final List keys) { - final ArrayList filteredKeys = CollectionUtils.newArrayList(); + final ArrayList filteredKeys = new ArrayList<>(); for (final Key key : keys) { if (key.isSpacer()) { continue; @@ -55,15 +54,15 @@ public final class ActualKeyboardBuilder extends AbstractKeyboardBuilder { final ArrayList filteredSortedKeys = filterOutSpacer(sortedKeys); // Grouping keys into rows. - final ArrayList> rows = CollectionUtils.newArrayList(); - ArrayList elements = CollectionUtils.newArrayList(); + final ArrayList> rows = new ArrayList<>(); + ArrayList elements = new ArrayList<>(); int lastY = filteredSortedKeys.get(0).getY(); for (final Key key : filteredSortedKeys) { if (lastY != key.getY()) { // A new row is starting. lastY = key.getY(); rows.add(elements); - elements = CollectionUtils.newArrayList(); + elements = new ArrayList<>(); } elements.add(key); } diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKey.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKey.java index ad08ba5a6..0e1c71cd1 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKey.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKey.java @@ -18,7 +18,6 @@ package com.android.inputmethod.keyboard.layout.expected; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.internal.MoreKeySpec; -import com.android.inputmethod.latin.utils.CollectionUtils; import java.util.ArrayList; import java.util.Arrays; @@ -73,9 +72,8 @@ public class ExpectedKey { // The additional more keys can be defined independently from other more keys. // The position of the additional more keys in the long press popup keyboard can be // controlled by specifying special marker "%" in the usual more keys definitions. - final ArrayList moreKeysList = CollectionUtils.newArrayList(); - final ArrayList additionalMoreKeys = - CollectionUtils.newArrayList(); + final ArrayList moreKeysList = new ArrayList<>(); + final ArrayList additionalMoreKeys = new ArrayList<>(); int firstAdditionalMoreKeyIndex = -1; for (int index = 0; index < moreKeys.length; index++) { final ExpectedKey moreKey = moreKeys[index]; diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java index e06d34d67..9b7de88ea 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java @@ -16,8 +16,6 @@ package com.android.inputmethod.keyboard.layout.expected; -import com.android.inputmethod.latin.utils.CollectionUtils; - import java.util.ArrayList; import java.util.Arrays; import java.util.Locale; @@ -116,7 +114,7 @@ public final class ExpectedKeyboardBuilder extends AbstractKeyboardBuilder list = CollectionUtils.newArrayList(); + final ArrayList list = new ArrayList<>(); for (final Object key : keys) { if (key instanceof ExpectedKey) { list.add((ExpectedKey)key); diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java index 3349a3247..28cce834c 100644 --- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java +++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java @@ -119,7 +119,7 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { final File file = File.createTempFile(dictId, TEST_DICT_FILE_EXTENSION, getContext().getCacheDir()); FileUtils.deleteRecursively(file); - Map attributeMap = new HashMap(); + Map attributeMap = new HashMap<>(); attributeMap.put(DictionaryHeader.DICTIONARY_ID_KEY, dictId); attributeMap.put(DictionaryHeader.DICTIONARY_VERSION_KEY, String.valueOf(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()))); @@ -333,7 +333,7 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { setCurrentTimeForTestMode(mCurrentTime); final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); - final ArrayList words = new ArrayList(); + final ArrayList words = new ArrayList<>(); for (int i = 0; i < unigramCount; i++) { final String word = CodePointUtils.generateWord(random, codePointSet); @@ -456,8 +456,8 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { setCurrentTimeForTestMode(mCurrentTime); final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); - final ArrayList words = new ArrayList(); - final ArrayList> bigrams = new ArrayList>(); + final ArrayList words = new ArrayList<>(); + final ArrayList> bigrams = new ArrayList<>(); for (int i = 0; i < unigramCount; ++i) { final String word = CodePointUtils.generateWord(random, codePointSet); @@ -471,7 +471,7 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { } final String word0 = words.get(word0Index); final String word1 = words.get(word1Index); - final Pair bigram = new Pair(word0, word1); + final Pair bigram = new Pair<>(word0, word1); bigrams.add(bigram); } @@ -535,7 +535,7 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { setCurrentTimeForTestMode(mCurrentTime); final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); - final ArrayList words = new ArrayList(); + final ArrayList words = new ArrayList<>(); for (int i = 0; i < unigramCount; i++) { final String word = CodePointUtils.generateWord(random, codePointSet); words.add(word); diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java index 79384092a..ccede0e39 100644 --- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java +++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java @@ -72,7 +72,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { getContext().getCacheDir()); file.delete(); file.mkdir(); - Map attributeMap = new HashMap(); + Map attributeMap = new HashMap<>(); if (BinaryDictionaryUtils.createEmptyDictFile(file.getAbsolutePath(), formatVersion, Locale.ENGLISH, attributeMap)) { return file; @@ -287,7 +287,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { 0 /* offset */, dictFile.length(), true /* useFullEditDistance */, Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */); - final HashMap probabilityMap = new HashMap(); + final HashMap probabilityMap = new HashMap<>(); // Test a word that isn't contained within the dictionary. final Random random = new Random(seed); final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); @@ -405,12 +405,11 @@ public class BinaryDictionaryTests extends AndroidTestCase { 0 /* offset */, dictFile.length(), true /* useFullEditDistance */, Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */); - final ArrayList words = new ArrayList(); - final ArrayList> bigramWords = new ArrayList>(); + final ArrayList words = new ArrayList<>(); + final ArrayList> bigramWords = new ArrayList<>(); final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); - final HashMap unigramProbabilities = new HashMap(); - final HashMap, Integer> bigramProbabilities = - new HashMap, Integer>(); + final HashMap unigramProbabilities = new HashMap<>(); + final HashMap, Integer> bigramProbabilities = new HashMap<>(); for (int i = 0; i < wordCount; ++i) { final String word = CodePointUtils.generateWord(random, codePointSet); @@ -426,7 +425,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { if (TextUtils.equals(word0, word1)) { continue; } - final Pair bigram = new Pair(word0, word1); + final Pair bigram = new Pair<>(word0, word1); bigramWords.add(bigram); final int unigramProbability = unigramProbabilities.get(word1); final int bigramProbability = @@ -629,12 +628,11 @@ public class BinaryDictionaryTests extends AndroidTestCase { 0 /* offset */, dictFile.length(), true /* useFullEditDistance */, Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */); - final ArrayList words = new ArrayList(); - final ArrayList> bigramWords = new ArrayList>(); + final ArrayList words = new ArrayList<>(); + final ArrayList> bigramWords = new ArrayList<>(); final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); - final HashMap unigramProbabilities = new HashMap(); - final HashMap, Integer> bigramProbabilities = - new HashMap, Integer>(); + final HashMap unigramProbabilities = new HashMap<>(); + final HashMap, Integer> bigramProbabilities = new HashMap<>(); for (int i = 0; i < wordCount; ++i) { final String word = CodePointUtils.generateWord(random, codePointSet); @@ -650,7 +648,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { if (TextUtils.equals(word0, word1)) { continue; } - final Pair bigram = new Pair(word0, word1); + final Pair bigram = new Pair<>(word0, word1); bigramWords.add(bigram); final int unigramProbability = unigramProbabilities.get(word1); final int bigramProbability = @@ -707,12 +705,11 @@ public class BinaryDictionaryTests extends AndroidTestCase { BinaryDictionary binaryDictionary = new BinaryDictionary(dictFile.getAbsolutePath(), 0 /* offset */, dictFile.length(), true /* useFullEditDistance */, Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */); - final ArrayList words = new ArrayList(); - final ArrayList> bigramWords = new ArrayList>(); + final ArrayList words = new ArrayList<>(); + final ArrayList> bigramWords = new ArrayList<>(); final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); - final HashMap unigramProbabilities = new HashMap(); - final HashMap, Integer> bigramProbabilities = - new HashMap, Integer>(); + final HashMap unigramProbabilities = new HashMap<>(); + final HashMap, Integer> bigramProbabilities = new HashMap<>(); for (int i = 0; i < initialUnigramCount; ++i) { final String word = CodePointUtils.generateWord(random, codePointSet); words.add(word); @@ -751,7 +748,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { final int unigramProbability = unigramProbabilities.get(word1); final int bigramProbability = unigramProbability + random.nextInt(0xFF - unigramProbability); - final Pair bigram = new Pair(word0, word1); + final Pair bigram = new Pair<>(word0, word1); bigramWords.add(bigram); bigramProbabilities.put(bigram, bigramProbability); addBigramWords(binaryDictionary, word0, word1, bigramProbability); @@ -817,8 +814,8 @@ public class BinaryDictionaryTests extends AndroidTestCase { fail("IOException while writing an initial dictionary : " + e); } - final ArrayList words = new ArrayList(); - final HashMap unigramProbabilities = new HashMap(); + final ArrayList words = new ArrayList<>(); + final HashMap unigramProbabilities = new HashMap<>(); final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); BinaryDictionary binaryDictionary; @@ -868,8 +865,8 @@ public class BinaryDictionaryTests extends AndroidTestCase { fail("IOException while writing an initial dictionary : " + e); } - final ArrayList words = new ArrayList(); - final HashSet> bigrams = new HashSet>(); + final ArrayList words = new ArrayList<>(); + final HashSet> bigrams = new HashSet<>(); final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); BinaryDictionary binaryDictionary; @@ -889,18 +886,18 @@ public class BinaryDictionaryTests extends AndroidTestCase { if (TextUtils.equals(word0, word1)) { continue; } - bigrams.add(new Pair(word0, word1)); + bigrams.add(new Pair<>(word0, word1)); final int bigramProbability = random.nextInt(0xF); addBigramWords(binaryDictionary, word0, word1, bigramProbability); } - assertEquals(new HashSet(words).size(), Integer.parseInt( + assertEquals(new HashSet<>(words).size(), Integer.parseInt( binaryDictionary.getPropertyForTest(BinaryDictionary.UNIGRAM_COUNT_QUERY))); - assertEquals(new HashSet>(bigrams).size(), Integer.parseInt( + assertEquals(new HashSet<>(bigrams).size(), Integer.parseInt( binaryDictionary.getPropertyForTest(BinaryDictionary.BIGRAM_COUNT_QUERY))); binaryDictionary.flushWithGC(); - assertEquals(new HashSet(words).size(), Integer.parseInt( + assertEquals(new HashSet<>(words).size(), Integer.parseInt( binaryDictionary.getPropertyForTest(BinaryDictionary.UNIGRAM_COUNT_QUERY))); - assertEquals(new HashSet>(bigrams).size(), Integer.parseInt( + assertEquals(new HashSet<>(bigrams).size(), Integer.parseInt( binaryDictionary.getPropertyForTest(BinaryDictionary.BIGRAM_COUNT_QUERY))); binaryDictionary.close(); } @@ -929,9 +926,8 @@ public class BinaryDictionaryTests extends AndroidTestCase { } final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); - final HashMap unigramProbabilities = new HashMap(); - final HashMap, Integer> bigramProbabilities = - new HashMap, Integer>(); + final HashMap unigramProbabilities = new HashMap<>(); + final HashMap, Integer> bigramProbabilities = new HashMap<>(); final LanguageModelParam[] languageModelParams = new LanguageModelParam[lmParamCount]; String prevWord = null; @@ -946,7 +942,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { } else { languageModelParams[i] = new LanguageModelParam(prevWord, word, probability, bigramProbability, BinaryDictionary.NOT_A_VALID_TIMESTAMP); - bigramProbabilities.put(new Pair(prevWord, word), + bigramProbabilities.put(new Pair<>(prevWord, word), bigramProbability); } prevWord = (random.nextDouble() < bigramContinueRate) ? word : null; @@ -1001,11 +997,10 @@ public class BinaryDictionaryTests extends AndroidTestCase { final WordProperty invalidWordProperty = binaryDictionary.getWordProperty("dummyWord"); assertFalse(invalidWordProperty.isValid()); - final ArrayList words = new ArrayList(); - final HashMap wordProbabilities = new HashMap(); - final HashMap> bigrams = new HashMap>(); - final HashMap, Integer> bigramProbabilities = - new HashMap, Integer>(); + final ArrayList words = new ArrayList<>(); + final HashMap wordProbabilities = new HashMap<>(); + final HashMap> bigrams = new HashMap<>(); + final HashMap, Integer> bigramProbabilities = new HashMap<>(); for (int i = 0; i < UNIGRAM_COUNT; i++) { final String word = CodePointUtils.generateWord(random, codePointSet); @@ -1049,11 +1044,11 @@ public class BinaryDictionaryTests extends AndroidTestCase { binaryDictionary.flushWithGC(); } if (!bigrams.containsKey(word0)) { - final HashSet bigramWord1s = new HashSet(); + final HashSet bigramWord1s = new HashSet<>(); bigrams.put(word0, bigramWord1s); } bigrams.get(word0).add(word1); - bigramProbabilities.put(new Pair(word0, word1), bigramProbability); + bigramProbabilities.put(new Pair<>(word0, word1), bigramProbability); } for (int i = 0; i < words.size(); i++) { @@ -1068,8 +1063,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { final String word1 = wordProperty.mBigrams.get(j).mWord; assertTrue(bigramWord1s.contains(word1)); if (canCheckBigramProbability(formatVersion)) { - final int bigramProbability = bigramProbabilities.get( - new Pair(word0, word1)); + final int bigramProbability = bigramProbabilities.get(new Pair<>(word0, word1)); assertEquals(bigramProbability, wordProperty.mBigrams.get(j).getProbability()); } } @@ -1103,12 +1097,11 @@ public class BinaryDictionaryTests extends AndroidTestCase { final WordProperty invalidWordProperty = binaryDictionary.getWordProperty("dummyWord"); assertFalse(invalidWordProperty.isValid()); - final ArrayList words = new ArrayList(); - final HashMap wordProbabilitiesToCheckLater = - new HashMap(); - final HashMap> bigrams = new HashMap>(); + final ArrayList words = new ArrayList<>(); + final HashMap wordProbabilitiesToCheckLater = new HashMap<>(); + final HashMap> bigrams = new HashMap<>(); final HashMap, Integer> bigramProbabilitiesToCheckLater = - new HashMap, Integer>(); + new HashMap<>(); for (int i = 0; i < UNIGRAM_COUNT; i++) { final String word = CodePointUtils.generateWord(random, codePointSet); @@ -1137,17 +1130,16 @@ public class BinaryDictionaryTests extends AndroidTestCase { binaryDictionary.flushWithGC(); } if (!bigrams.containsKey(word0)) { - final HashSet bigramWord1s = new HashSet(); + final HashSet bigramWord1s = new HashSet<>(); bigrams.put(word0, bigramWord1s); } bigrams.get(word0).add(word1); - bigramProbabilitiesToCheckLater.put( - new Pair(word0, word1), bigramProbability); + bigramProbabilitiesToCheckLater.put(new Pair<>(word0, word1), bigramProbability); } - final HashSet wordSet = new HashSet(words); + final HashSet wordSet = new HashSet<>(words); final HashSet> bigramSet = - new HashSet>(bigramProbabilitiesToCheckLater.keySet()); + new HashSet<>(bigramProbabilitiesToCheckLater.keySet()); int token = 0; do { final BinaryDictionary.GetNextWordPropertyResult result = @@ -1161,7 +1153,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { for (int j = 0; j < wordProperty.mBigrams.size(); j++) { final String word1 = wordProperty.mBigrams.get(j).mWord; assertTrue(bigramWord1s.contains(word1)); - final Pair bigram = new Pair(word0, word1); + final Pair bigram = new Pair<>(word0, word1); if (canCheckBigramProbability(formatVersion)) { final int bigramProbability = bigramProbabilitiesToCheckLater.get(bigram); assertEquals(bigramProbability, wordProperty.mBigrams.get(j).getProbability()); @@ -1212,7 +1204,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { binaryDictionary.addUnigramEntry("aaa", unigramProbability, "yyy", shortcutProbability, false /* isBeginningOfSentence */, false /* isNotAWord */, false /* isBlacklisted */, 0 /* timestamp */); - final HashMap shortcutTargets = new HashMap(); + final HashMap shortcutTargets = new HashMap<>(); shortcutTargets.put("zzz", updatedShortcutProbability); shortcutTargets.put("yyy", shortcutProbability); wordProperty = binaryDictionary.getWordProperty("aaa"); @@ -1250,10 +1242,9 @@ public class BinaryDictionaryTests extends AndroidTestCase { final int codePointSetSize = 20; final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); - final ArrayList words = new ArrayList(); - final HashMap unigramProbabilities = new HashMap(); - final HashMap> shortcutTargets = - new HashMap>(); + final ArrayList words = new ArrayList<>(); + final HashMap unigramProbabilities = new HashMap<>(); + final HashMap> shortcutTargets = new HashMap<>(); File dictFile = null; try { @@ -1287,8 +1278,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { final HashMap shortcutTargetsOfWord = shortcutTargets.get(word); shortcutTargetsOfWord.put(shortcutTarget, shortcutProbability); } else { - final HashMap shortcutTargetsOfWord = - new HashMap(); + final HashMap shortcutTargetsOfWord = new HashMap<>(); shortcutTargetsOfWord.put(shortcutTarget, shortcutProbability); shortcutTargets.put(word, shortcutTargetsOfWord); } @@ -1386,12 +1376,11 @@ public class BinaryDictionaryTests extends AndroidTestCase { 0 /* offset */, dictFile.length(), true /* useFullEditDistance */, Locale.getDefault(), TEST_LOCALE, true /* isUpdatable */); - final ArrayList words = new ArrayList(); - final ArrayList> bigrams = new ArrayList>(); + final ArrayList words = new ArrayList<>(); + final ArrayList> bigrams = new ArrayList<>(); final int[] codePointSet = CodePointUtils.generateCodePointSet(codePointSetSize, random); - final HashMap unigramProbabilities = new HashMap(); - final HashMap, Integer> bigramProbabilities = - new HashMap, Integer>(); + final HashMap unigramProbabilities = new HashMap<>(); + final HashMap, Integer> bigramProbabilities = new HashMap<>(); for (int i = 0; i < UNIGRAM_COUNT; i++) { final String word = CodePointUtils.generateWord(random, codePointSet); @@ -1419,7 +1408,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { if (binaryDictionary.needsToRunGC(true /* mindsBlockByGC */)) { binaryDictionary.flushWithGC(); } - final Pair bigram = new Pair(word0, word1); + final Pair bigram = new Pair<>(word0, word1); bigrams.add(bigram); bigramProbabilities.put(bigram, bigramProbability); } diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTestsLanguageWithoutSpaces.java b/tests/src/com/android/inputmethod/latin/InputLogicTestsLanguageWithoutSpaces.java index e38ba721e..2560407dc 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTestsLanguageWithoutSpaces.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTestsLanguageWithoutSpaces.java @@ -19,8 +19,6 @@ package com.android.inputmethod.latin; import android.test.suitebuilder.annotation.LargeTest; import android.view.inputmethod.BaseInputConnection; -import com.android.inputmethod.latin.suggestions.SuggestionStripView; - @LargeTest public class InputLogicTestsLanguageWithoutSpaces extends InputTestsBase { public void testAutoCorrectForLanguageWithoutSpaces() { diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java b/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java index 68b6ee674..914b0bb23 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java @@ -18,8 +18,6 @@ package com.android.inputmethod.latin; import android.test.suitebuilder.annotation.LargeTest; -import com.android.inputmethod.latin.suggestions.SuggestionStripView; - @LargeTest public class InputLogicTestsNonEnglish extends InputTestsBase { final String NEXT_WORD_PREDICTION_OPTION = "next_word_prediction"; diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTestsReorderingMyanmar.java b/tests/src/com/android/inputmethod/latin/InputLogicTestsReorderingMyanmar.java index bb36a2a16..61eae4e8b 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTestsReorderingMyanmar.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTestsReorderingMyanmar.java @@ -77,6 +77,7 @@ import android.util.Pair; */ @LargeTest +@SuppressWarnings("rawtypes") public class InputLogicTestsReorderingMyanmar extends InputTestsBase { // The tests are formatted as follows. // Each test is an entry in the array of Pair arrays. @@ -202,6 +203,7 @@ public class InputLogicTestsReorderingMyanmar extends InputTestsBase { */ }; + @SuppressWarnings("unchecked") private void doMyanmarTest(final int testNumber, final Pair[] test) { int stepNumber = 0; for (final Pair step : test) { diff --git a/tests/src/com/android/inputmethod/latin/LatinImeStressTests.java b/tests/src/com/android/inputmethod/latin/LatinImeStressTests.java index 0a29d8326..f5e993de8 100644 --- a/tests/src/com/android/inputmethod/latin/LatinImeStressTests.java +++ b/tests/src/com/android/inputmethod/latin/LatinImeStressTests.java @@ -30,7 +30,6 @@ public class LatinImeStressTests extends InputTestsBase { final int maxWordCountToTypeInEachIteration = 20; final long seed = System.currentTimeMillis(); final Random random = new Random(seed); - final int codePointSetSize = 30; final int[] codePointSet = CodePointUtils.LATIN_ALPHABETS_LOWER; for (int i = 0; i < switchCount; ++i) { changeLanguageWithoutWait(locales[random.nextInt(locales.length)], diff --git a/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java b/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java index 8fe473523..330bedd6b 100644 --- a/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java +++ b/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java @@ -16,12 +16,10 @@ package com.android.inputmethod.latin; -import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; - import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; -import com.android.inputmethod.latin.utils.CollectionUtils; +import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import java.util.ArrayList; import java.util.Locale; @@ -33,7 +31,7 @@ public class SuggestedWordsTests extends AndroidTestCase { final String TYPED_WORD = "typed"; final int TYPED_WORD_FREQ = 5; final int NUMBER_OF_ADDED_SUGGESTIONS = 5; - final ArrayList list = CollectionUtils.newArrayList(); + final ArrayList list = new ArrayList<>(); list.add(new SuggestedWordInfo(TYPED_WORD, TYPED_WORD_FREQ, SuggestedWordInfo.KIND_TYPED, null /* sourceDict */, SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */, diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java index f29fc21c1..4b332ca84 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java @@ -28,10 +28,8 @@ import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer; import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions; import com.android.inputmethod.latin.makedict.FusionDictionary.PtNode; import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray; -import com.android.inputmethod.latin.makedict.UnsupportedFormatException; import com.android.inputmethod.latin.utils.BinaryDictionaryUtils; import com.android.inputmethod.latin.utils.ByteArrayDictBuffer; -import com.android.inputmethod.latin.utils.CollectionUtils; import java.io.File; import java.io.IOException; @@ -61,15 +59,12 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { private static final int NUM_OF_NODES_HAVING_SHORTCUTS = 50; private static final int NUM_OF_SHORTCUTS = 5; - private static final ArrayList sWords = CollectionUtils.newArrayList(); - private static final ArrayList sWordsWithVariousCodePoints = - CollectionUtils.newArrayList(); - private static final SparseArray> sEmptyBigrams = - CollectionUtils.newSparseArray(); - private static final SparseArray> sStarBigrams = CollectionUtils.newSparseArray(); - private static final SparseArray> sChainBigrams = - CollectionUtils.newSparseArray(); - private static final HashMap> sShortcuts = CollectionUtils.newHashMap(); + private static final ArrayList sWords = new ArrayList<>(); + private static final ArrayList sWordsWithVariousCodePoints = new ArrayList<>(); + private static final SparseArray> sEmptyBigrams = new SparseArray<>(); + private static final SparseArray> sStarBigrams = new SparseArray<>(); + private static final SparseArray> sChainBigrams = new SparseArray<>(); + private static final HashMap> sShortcuts = new HashMap<>(); public BinaryDictDecoderEncoderTests() { this(System.currentTimeMillis(), DEFAULT_MAX_UNIGRAMS); @@ -125,7 +120,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { private void generateWords(final int number, final Random random) { final int[] codePointSet = CodePointUtils.generateCodePointSet(DEFAULT_CODE_POINT_SET_SIZE, random); - final Set wordSet = CollectionUtils.newHashSet(); + final Set wordSet = new HashSet<>(); while (wordSet.size() < number) { wordSet.add(CodePointUtils.generateWord(random, codePointSet)); } @@ -147,7 +142,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { final List words, final HashMap> shortcutMap) { for (int i = 0; i < number; ++i) { final String word = words.get(i); - final ArrayList shortcuts = CollectionUtils.newArrayList(); + final ArrayList shortcuts = new ArrayList<>(); if (shortcutMap != null && shortcutMap.containsKey(word)) { for (final String shortcut : shortcutMap.get(word)) { shortcuts.add(new WeightedString(shortcut, UNIGRAM_FREQ)); @@ -325,7 +320,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { } public void testReadAndWriteWithByteBuffer() { - final List results = CollectionUtils.newArrayList(); + final List results = new ArrayList<>(); runReadAndWriteTests(results, BinaryDictUtils.USE_BYTE_BUFFER, BinaryDictUtils.VERSION2_OPTIONS); @@ -339,7 +334,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { } public void testReadAndWriteWithByteArray() { - final List results = CollectionUtils.newArrayList(); + final List results = new ArrayList<>(); runReadAndWriteTests(results, BinaryDictUtils.USE_BYTE_ARRAY, BinaryDictUtils.VERSION2_OPTIONS); @@ -362,8 +357,8 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { final TreeMap> resultBigrams, final boolean checkProbability) { // check unigrams - final Set actualWordsSet = new HashSet(resultWords.values()); - final Set expectedWordsSet = new HashSet(expectedWords); + final Set actualWordsSet = new HashSet<>(resultWords.values()); + final Set expectedWordsSet = new HashSet<>(expectedWords); assertEquals(actualWordsSet, expectedWordsSet); if (checkProbability) { for (int freq : resultFrequencies.values()) { @@ -372,7 +367,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { } // check bigrams - final HashMap> expBigrams = new HashMap>(); + final HashMap> expBigrams = new HashMap<>(); for (int i = 0; i < expectedBigrams.size(); ++i) { final String word1 = expectedWords.get(expectedBigrams.keyAt(i)); for (int w2 : expectedBigrams.valueAt(i)) { @@ -383,7 +378,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { } } - final HashMap> actBigrams = new HashMap>(); + final HashMap> actBigrams = new HashMap<>(); for (Entry> entry : resultBigrams.entrySet()) { final String word1 = resultWords.get(entry.getKey()); final int unigramFreq = resultFrequencies.get(entry.getKey()); @@ -407,10 +402,9 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { private long timeAndCheckReadUnigramsAndBigramsBinary(final File file, final List words, final SparseArray> bigrams, final int bufferType, final boolean checkProbability) { - final TreeMap resultWords = CollectionUtils.newTreeMap(); - final TreeMap> resultBigrams = - CollectionUtils.newTreeMap(); - final TreeMap resultFreqs = CollectionUtils.newTreeMap(); + final TreeMap resultWords = new TreeMap<>(); + final TreeMap> resultBigrams = new TreeMap<>(); + final TreeMap resultFreqs = new TreeMap<>(); long now = -1, diff = -1; try { @@ -468,7 +462,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { } public void testReadUnigramsAndBigramsBinaryWithByteBuffer() { - final ArrayList results = CollectionUtils.newArrayList(); + final ArrayList results = new ArrayList<>(); runReadUnigramsAndBigramsTests(results, BinaryDictUtils.USE_BYTE_BUFFER, BinaryDictUtils.VERSION2_OPTIONS); @@ -479,7 +473,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { } public void testReadUnigramsAndBigramsBinaryWithByteArray() { - final ArrayList results = CollectionUtils.newArrayList(); + final ArrayList results = new ArrayList<>(); runReadUnigramsAndBigramsTests(results, BinaryDictUtils.USE_BYTE_ARRAY, BinaryDictUtils.VERSION2_OPTIONS); @@ -590,7 +584,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { } public void testGetTerminalPosition() { - final ArrayList results = CollectionUtils.newArrayList(); + final ArrayList results = new ArrayList<>(); runGetTerminalPositionTests(BinaryDictUtils.USE_BYTE_ARRAY, BinaryDictUtils.VERSION2_OPTIONS); @@ -656,15 +650,15 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { 0 /* offset */, file.length(), true /* useFullEditDistance */, Locale.ENGLISH, dictName, false /* isUpdatable */); - final HashSet wordSet = new HashSet(words); - final HashSet> bigramSet = new HashSet>(); + final HashSet wordSet = new HashSet<>(words); + final HashSet> bigramSet = new HashSet<>(); for (int i = 0; i < words.size(); i++) { final List bigramList = bigrams.get(i); if (bigramList != null) { for (final Integer word1Index : bigramList) { final String word1 = words.get(word1Index); - bigramSet.add(new Pair(words.get(i), word1)); + bigramSet.add(new Pair<>(words.get(i), word1)); } } } @@ -689,7 +683,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { } for (int j = 0; j < wordProperty.mBigrams.size(); j++) { final String word1 = wordProperty.mBigrams.get(j).mWord; - final Pair bigram = new Pair(word0, word1); + final Pair bigram = new Pair<>(word0, word1); assertTrue(bigramSet.contains(bigram)); bigramSet.remove(bigram); } diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java index 6f8b07a34..96604a197 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java @@ -32,9 +32,6 @@ import java.nio.ByteBuffer; * TODO: Rename this class to DictDecoderUtils. */ public final class BinaryDictDecoderUtils { - - private static final boolean DBG = MakedictLog.DBG; - private BinaryDictDecoderUtils() { // This utility class is not publicly instantiable. } diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java index 39bd98bad..084371944 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java @@ -258,7 +258,7 @@ public class BinaryDictEncoderUtils { final PtNodeArray rootNodeArray) { final int treeSize = FusionDictionary.countPtNodes(rootNodeArray); MakedictLog.i("Counted nodes : " + treeSize); - final ArrayList flatTree = new ArrayList(treeSize); + final ArrayList flatTree = new ArrayList<>(treeSize); return flattenTreeInner(flatTree, rootNodeArray); } diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java index 42a50be66..9c3b37387 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java @@ -90,7 +90,7 @@ public final class BinaryDictIOUtils { final Map> bigrams) { int[] pushedChars = new int[FormatSpec.MAX_WORD_LENGTH + 1]; - Stack stack = new Stack(); + Stack stack = new Stack<>(); int index = 0; Position initPos = new Position(bodyOffset, 0); diff --git a/tests/src/com/android/inputmethod/latin/makedict/FusionDictionary.java b/tests/src/com/android/inputmethod/latin/makedict/FusionDictionary.java index f60b3af4f..4a8c178b5 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/FusionDictionary.java +++ b/tests/src/com/android/inputmethod/latin/makedict/FusionDictionary.java @@ -57,7 +57,7 @@ public final class FusionDictionary implements Iterable { int mCachedParentAddress = 0; public PtNodeArray() { - mData = new ArrayList(); + mData = new ArrayList<>(); } public PtNodeArray(ArrayList data) { Collections.sort(data, PTNODE_COMPARATOR); @@ -161,14 +161,14 @@ public final class FusionDictionary implements Iterable { // We don't want write permission to escape outside the package, so we return a copy if (null == mShortcutTargets) return null; final ArrayList copyOfShortcutTargets = - new ArrayList(mShortcutTargets); + new ArrayList<>(mShortcutTargets); return copyOfShortcutTargets; } public ArrayList getBigrams() { // We don't want write permission to escape outside the package, so we return a copy if (null == mBigrams) return null; - final ArrayList copyOfBigrams = new ArrayList(mBigrams); + final ArrayList copyOfBigrams = new ArrayList<>(mBigrams); return copyOfBigrams; } @@ -183,7 +183,7 @@ public final class FusionDictionary implements Iterable { */ public void addBigram(final String word, final ProbabilityInfo probabilityInfo) { if (mBigrams == null) { - mBigrams = new ArrayList(); + mBigrams = new ArrayList<>(); } WeightedString bigram = getBigram(word); if (bigram != null) { @@ -571,7 +571,6 @@ public final class FusionDictionary implements Iterable { /** * Helper method to find a word in a given branch. */ - @SuppressWarnings("unused") public static PtNode findWordInTree(PtNodeArray nodeArray, final String string) { int index = 0; final StringBuilder checker = DBG ? new StringBuilder() : null; @@ -651,7 +650,7 @@ public final class FusionDictionary implements Iterable { public DictionaryIterator(ArrayList ptRoot) { mCurrentString = new StringBuilder(); - mPositions = new LinkedList(); + mPositions = new LinkedList<>(); final Position rootPos = new Position(ptRoot); mPositions.add(rootPos); } diff --git a/tests/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java b/tests/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java index 7091c119e..65b84d5f7 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java +++ b/tests/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java @@ -20,7 +20,6 @@ import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.BinaryDictionary; import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.CharEncoding; import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer; -import com.android.inputmethod.latin.utils.CollectionUtils; import java.io.File; import java.io.FileNotFoundException; @@ -34,8 +33,6 @@ import java.util.Arrays; // TODO: Separate logics that are used only for testing. @UsedForTesting public class Ver2DictDecoder extends AbstractDictDecoder { - private static final String TAG = Ver2DictDecoder.class.getSimpleName(); - /** * A utility class for reading a PtNode. */ @@ -233,7 +230,7 @@ public class Ver2DictDecoder extends AbstractDictDecoder { final ArrayList shortcutTargets; if (0 != (flags & FormatSpec.FLAG_HAS_SHORTCUT_TARGETS)) { // readShortcut will add shortcuts to shortcutTargets. - shortcutTargets = new ArrayList(); + shortcutTargets = new ArrayList<>(); addressPointer += PtNodeReader.readShortcut(mDictBuffer, shortcutTargets); } else { shortcutTargets = null; @@ -241,7 +238,7 @@ public class Ver2DictDecoder extends AbstractDictDecoder { final ArrayList bigrams; if (0 != (flags & FormatSpec.FLAG_HAS_BIGRAMS)) { - bigrams = new ArrayList(); + bigrams = new ArrayList<>(); addressPointer += PtNodeReader.readBigramAddresses(mDictBuffer, bigrams, addressPointer); if (bigrams.size() >= FormatSpec.MAX_BIGRAMS_IN_A_PTNODE) { @@ -267,7 +264,7 @@ public class Ver2DictDecoder extends AbstractDictDecoder { final FusionDictionary fusionDict = new FusionDictionary(new FusionDictionary.PtNodeArray(), header.mDictionaryOptions); int token = 0; - final ArrayList wordProperties = CollectionUtils.newArrayList(); + final ArrayList wordProperties = new ArrayList<>(); do { final BinaryDictionary.GetNextWordPropertyResult result = binaryDictionary.getNextWordProperty(token); diff --git a/tests/src/com/android/inputmethod/latin/makedict/Ver2DictDecoderTests.java b/tests/src/com/android/inputmethod/latin/makedict/Ver2DictDecoderTests.java index 9dc2b1058..3882c2c55 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/Ver2DictDecoderTests.java +++ b/tests/src/com/android/inputmethod/latin/makedict/Ver2DictDecoderTests.java @@ -58,7 +58,6 @@ public class Ver2DictDecoderTests extends AndroidTestCase { } } - @SuppressWarnings("null") public void runTestOpenBuffer(final String testName, final DictionaryBufferFactory factory) { File testFile = null; try { @@ -102,7 +101,6 @@ public class Ver2DictDecoderTests extends AndroidTestCase { new DictionaryBufferFromWritableByteBufferFactory()); } - @SuppressWarnings("null") public void runTestGetBuffer(final String testName, final DictionaryBufferFactory factory) { File testFile = null; try { diff --git a/tests/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java b/tests/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java index f3fad7e99..5e8417ed6 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java +++ b/tests/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java @@ -18,7 +18,6 @@ package com.android.inputmethod.latin.makedict; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.BinaryDictionary; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.FileUtils; import java.io.File; @@ -31,8 +30,6 @@ import java.util.ArrayList; */ @UsedForTesting public class Ver4DictDecoder extends AbstractDictDecoder { - private static final String TAG = Ver4DictDecoder.class.getSimpleName(); - final File mDictDirectory; @UsedForTesting @@ -73,7 +70,7 @@ public class Ver4DictDecoder extends AbstractDictDecoder { final FusionDictionary fusionDict = new FusionDictionary(new FusionDictionary.PtNodeArray(), header.mDictionaryOptions); int token = 0; - final ArrayList wordProperties = CollectionUtils.newArrayList(); + final ArrayList wordProperties = new ArrayList<>(); do { final BinaryDictionary.GetNextWordPropertyResult result = binaryDictionary.getNextWordProperty(token); diff --git a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java index 7d3214a3d..8bcf14aa3 100644 --- a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java +++ b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java @@ -23,15 +23,14 @@ import android.util.Log; import com.android.inputmethod.latin.ExpandableBinaryDictionary; import com.android.inputmethod.latin.PrevWordsInfo; import com.android.inputmethod.latin.utils.BinaryDictionaryUtils; -import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.FileUtils; import java.io.File; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Random; -import java.util.Set; import java.util.concurrent.TimeUnit; /** @@ -102,11 +101,11 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { } private static List generateWords(final int number, final Random random) { - final Set wordSet = CollectionUtils.newHashSet(); + final HashSet wordSet = new HashSet<>(); while (wordSet.size() < number) { wordSet.add(generateWord(random.nextInt())); } - return new ArrayList(wordSet); + return new ArrayList<>(wordSet); } private static void addToDict(final UserHistoryDictionary dict, final List words) { diff --git a/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java b/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java index 7fd167977..1501e942a 100644 --- a/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java +++ b/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java @@ -45,27 +45,27 @@ public class AsyncResultHolderTests extends AndroidTestCase { } public void testGetWithoutSet() { - final AsyncResultHolder holder = new AsyncResultHolder(); + final AsyncResultHolder holder = new AsyncResultHolder<>(); final int resultValue = holder.get(DEFAULT_VALUE, TIMEOUT_IN_MILLISECONDS); assertEquals(DEFAULT_VALUE, resultValue); } public void testGetBeforeSet() { - final AsyncResultHolder holder = new AsyncResultHolder(); + final AsyncResultHolder holder = new AsyncResultHolder<>(); setAfterGivenTime(holder, SET_VALUE, TIMEOUT_IN_MILLISECONDS + MARGIN_IN_MILLISECONDS); final int resultValue = holder.get(DEFAULT_VALUE, TIMEOUT_IN_MILLISECONDS); assertEquals(DEFAULT_VALUE, resultValue); } public void testGetAfterSet() { - final AsyncResultHolder holder = new AsyncResultHolder(); + final AsyncResultHolder holder = new AsyncResultHolder<>(); holder.set(SET_VALUE); final int resultValue = holder.get(DEFAULT_VALUE, TIMEOUT_IN_MILLISECONDS); assertEquals(SET_VALUE, resultValue); } public void testGetBeforeTimeout() { - final AsyncResultHolder holder = new AsyncResultHolder(); + final AsyncResultHolder holder = new AsyncResultHolder<>(); setAfterGivenTime(holder, SET_VALUE, TIMEOUT_IN_MILLISECONDS - MARGIN_IN_MILLISECONDS); final int resultValue = holder.get(DEFAULT_VALUE, TIMEOUT_IN_MILLISECONDS); assertEquals(SET_VALUE, resultValue); diff --git a/tests/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtilsTests.java index d86639101..a333ee9bc 100644 --- a/tests/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtilsTests.java @@ -48,7 +48,7 @@ public class BinaryDictionaryUtilsTests extends AndroidTestCase { private File createEmptyVer4DictionaryAndGetFile(final String dictId) throws IOException { final File file = getDictFile(dictId); FileUtils.deleteRecursively(file); - Map attributeMap = new HashMap(); + Map attributeMap = new HashMap<>(); attributeMap.put(DictionaryHeader.DICTIONARY_ID_KEY, dictId); attributeMap.put(DictionaryHeader.DICTIONARY_VERSION_KEY, String.valueOf(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()))); diff --git a/tests/src/com/android/inputmethod/latin/utils/ResourceUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/ResourceUtilsTests.java index 3eb704093..8e764e40f 100644 --- a/tests/src/com/android/inputmethod/latin/utils/ResourceUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/utils/ResourceUtilsTests.java @@ -24,10 +24,10 @@ import java.util.HashMap; @SmallTest public class ResourceUtilsTests extends AndroidTestCase { public void testFindConstantForKeyValuePairsSimple() { - final HashMap anyKeyValue = CollectionUtils.newHashMap(); + final HashMap anyKeyValue = new HashMap<>(); anyKeyValue.put("anyKey", "anyValue"); final HashMap nullKeyValue = null; - final HashMap emptyKeyValue = CollectionUtils.newHashMap(); + final HashMap emptyKeyValue = new HashMap<>(); final String[] nullArray = null; assertNull(ResourceUtils.findConstantForKeyValuePairs(anyKeyValue, nullArray)); @@ -48,7 +48,7 @@ public class ResourceUtilsTests extends AndroidTestCase { "HARDWARE=mako,0.5", }; - final HashMap keyValues = CollectionUtils.newHashMap(); + final HashMap keyValues = new HashMap<>(); keyValues.put(HARDWARE_KEY, "grouper"); assertEquals("0.3", ResourceUtils.findConstantForKeyValuePairs(keyValues, array)); keyValues.put(HARDWARE_KEY, "mako"); @@ -88,7 +88,7 @@ public class ResourceUtilsTests extends AndroidTestCase { "HARDWARE=mantaray:MODEL=Nexus 10:MANUFACTURER=samsung,0.2" }; - final HashMap keyValues = CollectionUtils.newHashMap(); + final HashMap keyValues = new HashMap<>(); keyValues.put(HARDWARE_KEY, "grouper"); keyValues.put(MODEL_KEY, "Nexus 7"); keyValues.put(MANUFACTURER_KEY, "asus"); @@ -126,7 +126,7 @@ public class ResourceUtilsTests extends AndroidTestCase { "HARDWARE=manta.*:MODEL=Nexus 10:MANUFACTURER=samsung,0.2" }; - final HashMap keyValues = CollectionUtils.newHashMap(); + final HashMap keyValues = new HashMap<>(); keyValues.put(HARDWARE_KEY, "grouper"); keyValues.put(MODEL_KEY, "Nexus 7"); keyValues.put(MANUFACTURER_KEY, "asus"); diff --git a/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguagetUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguagetUtilsTests.java index ff1103e4f..4156de78b 100644 --- a/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguagetUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/utils/SpacebarLanguagetUtilsTests.java @@ -31,7 +31,7 @@ import java.util.Locale; @SmallTest public class SpacebarLanguagetUtilsTests extends AndroidTestCase { // All input method subtypes of LatinIME. - private final ArrayList mSubtypesList = CollectionUtils.newArrayList(); + private final ArrayList mSubtypesList = new ArrayList<>(); private RichInputMethodManager mRichImm; private Resources mRes; diff --git a/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java index ee345905c..8e409ab99 100644 --- a/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtilsTests.java @@ -31,7 +31,7 @@ import java.util.Locale; @SmallTest public class SubtypeLocaleUtilsTests extends AndroidTestCase { // All input method subtypes of LatinIME. - private final ArrayList mSubtypesList = CollectionUtils.newArrayList(); + private final ArrayList mSubtypesList = new ArrayList<>(); private RichInputMethodManager mRichImm; private Resources mRes; diff --git a/tools/dicttool/Android.mk b/tools/dicttool/Android.mk index 10104cf33..a3698bdd1 100644 --- a/tools/dicttool/Android.mk +++ b/tools/dicttool/Android.mk @@ -49,7 +49,6 @@ LATINIME_SRC_FILES_FOR_DICTTOOL := \ latin/WordComposer.java \ latin/settings/NativeSuggestOptions.java \ latin/utils/BinaryDictionaryUtils.java \ - latin/utils/CollectionUtils.java \ latin/utils/CombinedFormatUtils.java \ latin/utils/CoordinateUtils.java \ latin/utils/FileUtils.java \ diff --git a/tools/dicttool/compat/android/util/SparseArray.java b/tools/dicttool/compat/android/util/SparseArray.java index 6c76f19f4..9efbd39c7 100644 --- a/tools/dicttool/compat/android/util/SparseArray.java +++ b/tools/dicttool/compat/android/util/SparseArray.java @@ -16,8 +16,6 @@ package android.util; -import com.android.inputmethod.latin.utils.CollectionUtils; - import java.util.ArrayList; import java.util.Collections; @@ -30,8 +28,8 @@ public class SparseArray { } public SparseArray(final int initialCapacity) { - mKeys = CollectionUtils.newArrayList(initialCapacity); - mValues = CollectionUtils.newArrayList(initialCapacity); + mKeys = new ArrayList<>(initialCapacity); + mValues = new ArrayList<>(initialCapacity); } public int size() { diff --git a/tools/dicttool/compat/android/util/SparseIntArray.java b/tools/dicttool/compat/android/util/SparseIntArray.java index ac8a04ceb..e4d3dfd07 100644 --- a/tools/dicttool/compat/android/util/SparseIntArray.java +++ b/tools/dicttool/compat/android/util/SparseIntArray.java @@ -24,7 +24,7 @@ public class SparseIntArray { } public SparseIntArray(final int initialCapacity) { - mArray = new SparseArray(initialCapacity); + mArray = new SparseArray<>(initialCapacity); } public int size() { diff --git a/tools/dicttool/compat/com/android/inputmethod/event/CombinerChain.java b/tools/dicttool/compat/com/android/inputmethod/event/CombinerChain.java index 538d759c8..458f22c45 100644 --- a/tools/dicttool/compat/com/android/inputmethod/event/CombinerChain.java +++ b/tools/dicttool/compat/com/android/inputmethod/event/CombinerChain.java @@ -16,8 +16,6 @@ package com.android.inputmethod.event; -import com.android.inputmethod.latin.utils.CollectionUtils; - import java.util.ArrayList; /** diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java index f9771c8dd..2cbc04154 100644 --- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java +++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java @@ -19,15 +19,14 @@ package com.android.inputmethod.latin.dicttool; import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils; import com.android.inputmethod.latin.makedict.BinaryDictIOUtils; import com.android.inputmethod.latin.makedict.DictDecoder; -import com.android.inputmethod.latin.makedict.FormatSpec; import com.android.inputmethod.latin.makedict.FusionDictionary; import com.android.inputmethod.latin.makedict.UnsupportedFormatException; import org.xml.sax.SAXException; -import java.io.File; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; +import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; @@ -54,7 +53,7 @@ public final class BinaryDictOffdeviceUtils { private final static int MAX_DECODE_DEPTH = 8; public static class DecoderChainSpec { - ArrayList mDecoderSpec = new ArrayList(); + ArrayList mDecoderSpec = new ArrayList<>(); File mFile; public DecoderChainSpec addStep(final String stepDescription) { mDecoderSpec.add(stepDescription); diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/CombinedInputOutput.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/CombinedInputOutput.java index 391328fda..6a0e1b7f0 100644 --- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/CombinedInputOutput.java +++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/CombinedInputOutput.java @@ -98,7 +98,7 @@ public class CombinedInputOutput { headerLine = reader.readLine(); } final String header[] = headerLine.split(","); - final HashMap attributes = new HashMap(); + final HashMap attributes = new HashMap<>(); for (String item : header) { final String keyValue[] = item.split("="); if (2 != keyValue.length) { @@ -115,8 +115,8 @@ public class CombinedInputOutput { String word = null; ProbabilityInfo probabilityInfo = new ProbabilityInfo(0); boolean isNotAWord = false; - ArrayList bigrams = new ArrayList(); - ArrayList shortcuts = new ArrayList(); + ArrayList bigrams = new ArrayList<>(); + ArrayList shortcuts = new ArrayList<>(); while (null != (line = reader.readLine())) { if (line.startsWith(COMMENT_LINE_STARTER)) continue; final String args[] = line.trim().split(","); @@ -128,8 +128,8 @@ public class CombinedInputOutput { dict.setBigram(word, s.mWord, s.mProbabilityInfo); } } - if (!shortcuts.isEmpty()) shortcuts = new ArrayList(); - if (!bigrams.isEmpty()) bigrams = new ArrayList(); + if (!shortcuts.isEmpty()) shortcuts = new ArrayList<>(); + if (!bigrams.isEmpty()) bigrams = new ArrayList<>(); isNotAWord = false; for (String param : args) { final String params[] = param.split("=", 2); @@ -223,7 +223,7 @@ public class CombinedInputOutput { */ public static void writeDictionaryCombined( final Writer destination, final FusionDictionary dict) throws IOException { - final TreeSet wordPropertiesInDict = new TreeSet(); + final TreeSet wordPropertiesInDict = new TreeSet<>(); for (final WordProperty wordProperty : dict) { // This for ordering by frequency, then by asciibetic order wordPropertiesInDict.add(wordProperty); diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/DictionaryMaker.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/DictionaryMaker.java index 8e8ab19e0..37c8d4184 100644 --- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/DictionaryMaker.java +++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/DictionaryMaker.java @@ -138,7 +138,7 @@ public class DictionaryMaker { } public Arguments(String[] argsArray) throws IOException { - final LinkedList args = new LinkedList(Arrays.asList(argsArray)); + final LinkedList args = new LinkedList<>(Arrays.asList(argsArray)); if (args.isEmpty()) { displayHelp(); } diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Dicttool.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Dicttool.java index cacee5268..8ae035f64 100644 --- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Dicttool.java +++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Dicttool.java @@ -29,8 +29,7 @@ public class Dicttool { abstract public String getHelp(); abstract public void run() throws Exception; } - static HashMap> sCommands = - new HashMap>(); + static HashMap> sCommands = new HashMap<>(); static { CommandList.populate(); } diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Diff.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Diff.java index cd3d4d393..94d1ae8bb 100644 --- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Diff.java +++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Diff.java @@ -85,8 +85,7 @@ public class Diff extends Dicttool.Command { private static void diffHeaders(final FusionDictionary dict0, final FusionDictionary dict1) { boolean hasDifferences = false; - final HashMap options1 = - new HashMap(dict1.mOptions.mAttributes); + final HashMap options1 = new HashMap<>(dict1.mOptions.mAttributes); for (final String optionKey : dict0.mOptions.mAttributes.keySet()) { if (!dict0.mOptions.mAttributes.get(optionKey).equals( dict1.mOptions.mAttributes.get(optionKey))) { diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Test.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Test.java index 33661c8d6..b6383d788 100644 --- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Test.java +++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Test.java @@ -53,8 +53,8 @@ public class Test extends Dicttool.Command { BinaryDictDecoderEncoderTests.class, BinaryDictEncoderFlattenTreeTests.class, }; - private ArrayList mAllTestMethods = new ArrayList(); - private ArrayList mUsedTestMethods = new ArrayList(); + private ArrayList mAllTestMethods = new ArrayList<>(); + private ArrayList mUsedTestMethods = new ArrayList<>(); public Test() { for (final Class c : sClassesToTest) { diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/XmlDictInputOutput.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/XmlDictInputOutput.java index 17e77dca1..7435fa7d6 100644 --- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/XmlDictInputOutput.java +++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/XmlDictInputOutput.java @@ -115,7 +115,7 @@ public class XmlDictInputOutput { } } } else if (ROOT_TAG.equals(localName)) { - final HashMap attributes = new HashMap(); + final HashMap attributes = new HashMap<>(); for (int attrIndex = 0; attrIndex < attrs.getLength(); ++attrIndex) { final String attrName = attrs.getLocalName(attrIndex); attributes.put(attrName, attrs.getValue(attrIndex)); @@ -172,7 +172,7 @@ public class XmlDictInputOutput { DST_ATTRIBUTE = dstAttribute; DST_FREQ = dstFreq; mSrc = null; - mAssocMap = new HashMap>(); + mAssocMap = new HashMap<>(); } @Override @@ -184,7 +184,7 @@ public class XmlDictInputOutput { int freq = getValueFromFreqString(attrs.getValue(uri, DST_FREQ)); WeightedString bigram = new WeightedString(dst, freq / XML_TO_MEMORY_RATIO); ArrayList bigramList = mAssocMap.get(mSrc); - if (null == bigramList) bigramList = new ArrayList(); + if (null == bigramList) bigramList = new ArrayList<>(); bigramList.add(bigram); mAssocMap.put(mSrc, bigramList); } @@ -352,7 +352,7 @@ public class XmlDictInputOutput { */ public static void writeDictionaryXml(Writer destination, FusionDictionary dict) throws IOException { - final TreeSet wordPropertiesInDict = new TreeSet(); + final TreeSet wordPropertiesInDict = new TreeSet<>(); for (WordProperty wordProperty : dict) { wordPropertiesInDict.add(wordProperty); } diff --git a/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java b/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java index 4f1273bdc..fccb654b0 100644 --- a/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java +++ b/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java @@ -16,12 +16,10 @@ package com.android.inputmethod.latin.dicttool; -import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.makedict.BinaryDictIOUtils; import com.android.inputmethod.latin.makedict.DictDecoder; import com.android.inputmethod.latin.makedict.DictEncoder; import com.android.inputmethod.latin.makedict.DictionaryHeader; -import com.android.inputmethod.latin.makedict.FormatSpec; import com.android.inputmethod.latin.makedict.FormatSpec.DictionaryOptions; import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions; import com.android.inputmethod.latin.makedict.FusionDictionary; @@ -32,8 +30,8 @@ import com.android.inputmethod.latin.makedict.Ver2DictEncoder; import junit.framework.TestCase; -import java.io.File; import java.io.BufferedOutputStream; +import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; diff --git a/tools/dicttool/tests/com/android/inputmethod/latin/makedict/FusionDictionaryTest.java b/tools/dicttool/tests/com/android/inputmethod/latin/makedict/FusionDictionaryTest.java index 6e81c3f3a..71f8ac8d4 100644 --- a/tools/dicttool/tests/com/android/inputmethod/latin/makedict/FusionDictionaryTest.java +++ b/tools/dicttool/tests/com/android/inputmethod/latin/makedict/FusionDictionaryTest.java @@ -32,7 +32,7 @@ import java.util.Random; * Unit tests for FusionDictionary. */ public class FusionDictionaryTest extends TestCase { - private static final ArrayList sWords = new ArrayList(); + private static final ArrayList sWords = new ArrayList<>(); private static final int MAX_UNIGRAMS = 1000; private void prepare(final long seed) { diff --git a/tools/make-keyboard-text/res/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.tmpl b/tools/make-keyboard-text/res/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.tmpl index 2b5494fa5..6a7469ccb 100644 --- a/tools/make-keyboard-text/res/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.tmpl +++ b/tools/make-keyboard-text/res/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.tmpl @@ -16,8 +16,6 @@ package com.android.inputmethod.keyboard.internal; -import com.android.inputmethod.latin.utils.CollectionUtils; - import java.util.HashMap; import java.util.Locale; @@ -44,14 +42,12 @@ import java.util.Locale; */ public final class KeyboardTextsTable { // Name to index map. - private static final HashMap sNameToIndexesMap = CollectionUtils.newHashMap(); + private static final HashMap sNameToIndexesMap = new HashMap<>(); // Locale to texts table map. - private static final HashMap sLocaleToTextsTableMap = - CollectionUtils.newHashMap(); + private static final HashMap sLocaleToTextsTableMap = new HashMap<>(); // TODO: Remove this variable after debugging. // Texts table to locale maps. - private static final HashMap sTextsTableToLocaleMap = - CollectionUtils.newHashMap(); + private static final HashMap sTextsTableToLocaleMap = new HashMap<>(); public static String getText(final String name, final String[] textsTable) { final Integer indexObj = sNameToIndexesMap.get(name); diff --git a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/JarUtils.java b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/JarUtils.java index c947a63bf..abb33397b 100644 --- a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/JarUtils.java +++ b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/JarUtils.java @@ -61,7 +61,7 @@ public final class JarUtils { } public static ArrayList getEntryNameListing(final JarFile jar, final JarFilter filter) { - final ArrayList result = new ArrayList(); + final ArrayList result = new ArrayList<>(); final Enumeration entries = jar.entries(); while (entries.hasMoreElements()) { final JarEntry entry = entries.nextElement(); diff --git a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/LocaleUtils.java b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/LocaleUtils.java index 0dfa37667..c1a7ec5eb 100644 --- a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/LocaleUtils.java +++ b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/LocaleUtils.java @@ -35,7 +35,7 @@ public final class LocaleUtils { // Intentional empty constructor for utility class. } - private static final HashMap sLocaleCache = new HashMap(); + private static final HashMap sLocaleCache = new HashMap<>(); private static final int INDEX_LANGUAGE = 0; private static final int INDEX_SCRIPT = 1; diff --git a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/MakeKeyboardText.java b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/MakeKeyboardText.java index 36a03f8dc..6c15ce6bf 100644 --- a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/MakeKeyboardText.java +++ b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/MakeKeyboardText.java @@ -36,7 +36,7 @@ public class MakeKeyboardText { } public Options(final String[] argsArray) { - final LinkedList args = new LinkedList(Arrays.asList(argsArray)); + final LinkedList args = new LinkedList<>(Arrays.asList(argsArray)); String arg = null; String java = null; try { diff --git a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/MoreKeysResources.java b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/MoreKeysResources.java index c8cb4acec..563acc57e 100644 --- a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/MoreKeysResources.java +++ b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/MoreKeysResources.java @@ -43,12 +43,11 @@ public class MoreKeysResources { private final JarFile mJar; // String resources maps sorted by its language. The language is determined from the jar entry // name by calling {@link JarUtils#getLocaleFromEntryName(String)}. - private final TreeMap mResourcesMap = - new TreeMap(); + private final TreeMap mResourcesMap = new TreeMap<>(); // Default string resources map. private final StringResourceMap mDefaultResourceMap; // Histogram of string resource names. This is used to sort {@link #mSortedResourceNames}. - private final HashMap mNameHistogram = new HashMap(); + private final HashMap mNameHistogram = new HashMap<>(); // Sorted string resource names array; Descending order of histogram count. // The string resource name is specified as an attribute "name" in string resource files. // The string resource can be accessed by specifying name "!text/" @@ -68,7 +67,7 @@ public class MoreKeysResources { // Initialize name histogram and names list. final HashMap nameHistogram = mNameHistogram; - final ArrayList resourceNamesList = new ArrayList(); + final ArrayList resourceNamesList = new ArrayList<>(); for (final StringResource res : mDefaultResourceMap.getResources()) { nameHistogram.put(res.mName, 0); // Initialize histogram value. resourceNamesList.add(res.mName); diff --git a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/StringResourceMap.java b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/StringResourceMap.java index 6a79268e5..cf44f2cad 100644 --- a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/StringResourceMap.java +++ b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/StringResourceMap.java @@ -73,7 +73,7 @@ public class StringResourceMap { } mResources = Collections.unmodifiableList(handler.mResources); - final HashMap map = new HashMap(); + final HashMap map = new HashMap<>(); for (final StringResource res : mResources) { map.put(res.mName, res); } @@ -105,7 +105,7 @@ public class StringResourceMap { private static final String TAG_STRING = "string"; private static final String ATTR_NAME = "name"; - final ArrayList mResources = new ArrayList(); + final ArrayList mResources = new ArrayList<>(); private String mName; private final StringBuilder mValue = new StringBuilder();