Bug 956360 - Use Arrays.asList when possible. r=jchen
authorMarcos Cezar <marcos.cezar.mendes@gmail.com>
Tue, 04 Mar 2014 14:32:47 -0300
changeset 191215 82f3207d8070a4a8c51eb84698bc216722dcaa85
parent 191214 bc6ab94ec2a6deab576e1a5a4911621b8d17317f
child 191216 1d74cad8ff3225e47f553ea7fb58da8f752ad439
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs956360
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 956360 - Use Arrays.asList when possible. r=jchen
mobile/android/base/GeckoApp.java
mobile/android/base/browserid/verifier/BrowserIDRemoteVerifierClient.java
mobile/android/base/favicons/Favicons.java
mobile/android/base/health/BrowserHealthRecorder.java
mobile/android/base/sqlite/SQLiteBridge.java
mobile/android/base/sync/repositories/android/FormHistoryRepositorySession.java
mobile/android/base/sync/setup/activities/SendTabData.java
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -11,16 +11,17 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
@@ -673,20 +674,17 @@ public abstract class GeckoApp
                 } else {
                     // something went wrong.
                     Log.e(LOGTAG, "Received Contact:Add message with no email nor phone number");
                 }                
             } else if (event.equals("Intent:GetHandlers")) {
                 Intent intent = GeckoAppShell.getOpenURIIntent(sAppContext, message.optString("url"),
                     message.optString("mime"), message.optString("action"), message.optString("title"));
                 String[] handlers = GeckoAppShell.getHandlersForIntent(intent);
-                ArrayList<String> appList = new ArrayList<String>(handlers.length);
-                for (int i = 0; i < handlers.length; i++) {
-                    appList.add(handlers[i]);
-                }
+                List<String> appList = Arrays.asList(handlers);
                 JSONObject handlersJSON = new JSONObject();
                 handlersJSON.put("apps", new JSONArray(appList));
                 EventDispatcher.sendResponse(message, handlersJSON);
             } else if (event.equals("Intent:Open")) {
                 GeckoAppShell.openUriExternal(message.optString("url"),
                     message.optString("mime"), message.optString("packageName"),
                     message.optString("className"), message.optString("action"), message.optString("title"));
             } else if (event.equals("Intent:OpenForResult")) {
--- a/mobile/android/base/browserid/verifier/BrowserIDRemoteVerifierClient.java
+++ b/mobile/android/base/browserid/verifier/BrowserIDRemoteVerifierClient.java
@@ -5,16 +5,17 @@
 package org.mozilla.gecko.browserid.verifier;
 
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.security.GeneralSecurityException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import org.mozilla.gecko.background.common.log.Logger;
 import org.mozilla.gecko.browserid.verifier.BrowserIDVerifierException.BrowserIDVerifierErrorResponseException;
 import org.mozilla.gecko.browserid.verifier.BrowserIDVerifierException.BrowserIDVerifierMalformedResponseException;
 import org.mozilla.gecko.sync.ExtendedJSONObject;
 import org.mozilla.gecko.sync.net.BaseResource;
 import org.mozilla.gecko.sync.net.BaseResourceDelegate;
@@ -113,19 +114,19 @@ public class BrowserIDRemoteVerifierClie
     if (delegate == null) {
       throw new IllegalArgumentException("delegate cannot be null.");
     }
 
     BaseResource r = new BaseResource(verifierUri);
 
     r.delegate = new RemoteVerifierResourceDelegate(r, delegate);
 
-    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
-    nvps.add(new BasicNameValuePair("audience", audience));
-    nvps.add(new BasicNameValuePair("assertion", assertion));
+    List<NameValuePair> nvps = Arrays.asList(new NameValuePair[] {
+        new BasicNameValuePair("audience", audience),
+        new BasicNameValuePair("assertion", assertion) });
 
     try {
       r.post(new UrlEncodedFormEntity(nvps, "UTF-8"));
     } catch (UnsupportedEncodingException e) {
       delegate.handleError(e);
     }
   }
 }
--- a/mobile/android/base/favicons/Favicons.java
+++ b/mobile/android/base/favicons/Favicons.java
@@ -25,18 +25,20 @@ import android.graphics.BitmapFactory;
 import android.text.TextUtils;
 import android.util.Log;
 import android.util.SparseArray;
 
 import java.io.File;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 
 public class Favicons {
     private static final String LOGTAG = "GeckoFavicons";
 
     // A magic URL representing the app's own favicon, used for about: pages.
     private static final String BUILT_IN_FAVICON_URL = "about:favicon";
 
@@ -391,19 +393,19 @@ public class Favicons {
 
         // Initialize page mappings for each of our special pages.
         for (String url : AboutPages.getDefaultIconPages()) {
             sPageURLMappings.putWithoutEviction(url, BUILT_IN_FAVICON_URL);
         }
 
         // Load and cache the built-in favicon in each of its sizes.
         // TODO: don't open the zip twice!
-        ArrayList<Bitmap> toInsert = new ArrayList<Bitmap>(2);
-        toInsert.add(loadBrandingBitmap(context, "favicon64.png"));
-        toInsert.add(loadBrandingBitmap(context, "favicon32.png"));
+        List<Bitmap> toInsert = Arrays.asList(loadBrandingBitmap(context, "favicon64.png"),
+                                              loadBrandingBitmap(context, "favicon32.png"));
+
         putFaviconsInMemCache(BUILT_IN_FAVICON_URL, toInsert.iterator(), true);
     }
 
     /**
      * Compute a string like:
      * "jar:jar:file:///data/app/org.mozilla.firefox-1.apk!/assets/omni.ja!/chrome/chrome/content/branding/favicon64.png"
      */
     private static String getBrandingBitmapPath(Context context, String name) {
--- a/mobile/android/base/health/BrowserHealthRecorder.java
+++ b/mobile/android/base/health/BrowserHealthRecorder.java
@@ -9,16 +9,17 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.OutputStreamWriter;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Scanner;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.Distribution;
@@ -784,19 +785,19 @@ public class BrowserHealthRecorder imple
 
     private void initializeSessionsProvider() {
         this.storage.ensureMeasurementInitialized(
             MEASUREMENT_NAME_SESSIONS,
             MEASUREMENT_VERSION_SESSIONS,
             new MeasurementFields() {
                 @Override
                 public Iterable<FieldSpec> getFields() {
-                    ArrayList<FieldSpec> out = new ArrayList<FieldSpec>(2);
-                    out.add(new FieldSpec("normal", Field.TYPE_JSON_DISCRETE));
-                    out.add(new FieldSpec("abnormal", Field.TYPE_JSON_DISCRETE));
+                    List<FieldSpec> out = Arrays.asList(
+                        new FieldSpec("normal", Field.TYPE_JSON_DISCRETE),
+                        new FieldSpec("abnormal", Field.TYPE_JSON_DISCRETE));
                     return out;
                 }
         });
     }
 
     /**
      * Logic shared between crashed and normal sessions.
      */
--- a/mobile/android/base/sqlite/SQLiteBridge.java
+++ b/mobile/android/base/sqlite/SQLiteBridge.java
@@ -8,16 +8,17 @@ import android.content.ContentValues;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.database.sqlite.SQLiteException;
 import android.text.TextUtils;
 import android.util.Log;
 import org.mozilla.gecko.mozglue.RobocopTarget;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Map.Entry;
 
 /*
  * This class allows using the mozsqlite3 library included with Firefox
  * to read SQLite databases, instead of the Android SQLiteDataBase API,
  * which might use whatever outdated DB is present on the Android system.
  */
 public class SQLiteBridge {
@@ -195,19 +196,17 @@ public class SQLiteBridge {
                 sb.append(" = ?");
                 valueNames.add(val.toString());
             }
         }
 
         if (!TextUtils.isEmpty(whereClause)) {
             sb.append(" WHERE ");
             sb.append(whereClause);
-            for (int i = 0; i < whereArgs.length; i++) {
-                valueNames.add(whereArgs[i]);
-            }
+            valueNames.addAll(Arrays.asList(whereArgs));
         }
 
         String[] binds = new String[valueNames.size()];
         valueNames.toArray(binds);
 
         internalQuery(sb.toString(), binds);
         return (int)mQueryResults[RESULT_ROWS_CHANGED];
     }
--- a/mobile/android/base/sync/repositories/android/FormHistoryRepositorySession.java
+++ b/mobile/android/base/sync/repositories/android/FormHistoryRepositorySession.java
@@ -1,15 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.sync.repositories.android;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.concurrent.Callable;
 
 import org.mozilla.gecko.background.common.log.Logger;
 import org.mozilla.gecko.db.BrowserContract.DeletedFormHistory;
 import org.mozilla.gecko.db.BrowserContract.FormHistory;
 import org.mozilla.gecko.sync.repositories.InactiveSessionException;
 import org.mozilla.gecko.sync.repositories.NoContentProviderException;
@@ -308,19 +309,19 @@ public class FormHistoryRepositorySessio
 
     Callable<Cursor> deletedCallable = new Callable<Cursor>() {
       @Override
       public Cursor call() throws Exception {
         return deletedHelper.safeQuery(formsProvider, ".fetchSince(deleted)", null, deletedBetween(timestamp, sharedEnd), null, null);
       }
     };
 
-    ArrayList<Callable<Cursor>> callableCursors = new ArrayList<Callable<Cursor>>();
-    callableCursors.add(regularCallable);
-    callableCursors.add(deletedCallable);
+    @SuppressWarnings("unchecked")
+    List<Callable<Cursor>> callableCursors = Arrays.asList(regularCallable, deletedCallable);
+
     fetchHelper(delegate, sharedEnd, callableCursors);
   }
 
   @Override
   public void fetchAll(RepositorySessionFetchRecordsDelegate delegate) {
     Logger.trace(LOG_TAG, "Running fetchAll.");
     fetchSince(0, delegate);
   }
@@ -343,19 +344,19 @@ public class FormHistoryRepositorySessio
     Callable<Cursor> deletedCallable = new Callable<Cursor>() {
       @Override
       public Cursor call() throws Exception {
         String deletedWhere = where + " AND " + DeletedFormHistory.TIME_DELETED + " <= " + Long.toString(sharedEnd); // Milliseconds.
         return deletedHelper.safeQuery(formsProvider, ".fetch(deleted)", null, deletedWhere, guids, null);
       }
     };
 
-    ArrayList<Callable<Cursor>> callableCursors = new ArrayList<Callable<Cursor>>();
-    callableCursors.add(regularCallable);
-    callableCursors.add(deletedCallable);
+    @SuppressWarnings("unchecked")
+    List<Callable<Cursor>> callableCursors = Arrays.asList(regularCallable, deletedCallable);
+
     fetchHelper(delegate, sharedEnd, callableCursors);
   }
 
   protected static final String GUID_IS = FormHistory.GUID + " = ?";
 
   protected Record findExistingRecordByGuid(String guid)
       throws RemoteException, NullCursorException {
     Cursor cursor = null;
--- a/mobile/android/base/sync/setup/activities/SendTabData.java
+++ b/mobile/android/base/sync/setup/activities/SendTabData.java
@@ -1,15 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.sync.setup.activities;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import android.content.Intent;
 import android.os.Bundle;
 
 /**
  * A static factory that extracts (title, uri) pairs suitable for send tab from
  * Android intent instances.
@@ -45,17 +46,14 @@ public class SendTabData {
     // For title, prefer EXTRA_SUBJECT but accept EXTRA_TITLE.
     String theTitle = subject;
     if (theTitle == null) {
       theTitle = title;
     }
 
     // For URL, take first URL from EXTRA_TEXT, EXTRA_SUBJECT, and EXTRA_TITLE
     // (in that order).
-    List<String> strings = new ArrayList<String>();
-    strings.add(text);
-    strings.add(subject);
-    strings.add(title);
+    List<String> strings = Arrays.asList(text, subject, title);
     String theUri = new WebURLFinder(strings).bestWebURL();
 
     return new SendTabData(theTitle, theUri);
   }
 }