Bug 1081287: Use EnumMap where possible. r=rnewman
authorChris Kitching <chriskitching@linux.com>
Fri, 10 Oct 2014 21:01:01 +0100
changeset 209923 efd2ce78cdeb0fe686e3f35bdf97a209e2e9ce61
parent 209922 611ffa760b443c10e1d558a2250749c97b6ebc47
child 209924 1b962a92eff2f6f93b173ed5f664b218355c78a1
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersrnewman
bugs1081287
milestone35.0a1
Bug 1081287: Use EnumMap where possible. r=rnewman * * * Bug 1081287: Use EnumMap where possible in sync. r=rnewman * * * Bug 1081287: Use EnumMap where possible. r=rnewman * * * Bug 1081287: Use EnumMap where possible. r=rnewman * * * Bug 1081287: Use EnumMap where possible. r=rnewman
mobile/android/base/fxa/login/FxAccountLoginStateMachine.java
mobile/android/base/fxa/sync/FxAccountGlobalSession.java
mobile/android/base/home/RemoteTabsPanel.java
mobile/android/base/sync/GlobalSession.java
--- a/mobile/android/base/fxa/login/FxAccountLoginStateMachine.java
+++ b/mobile/android/base/fxa/login/FxAccountLoginStateMachine.java
@@ -1,16 +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.fxa.login;
 
 import java.security.NoSuchAlgorithmException;
-import java.util.HashSet;
+import java.util.EnumSet;
 import java.util.Set;
 
 import org.mozilla.gecko.background.fxa.FxAccountClient;
 import org.mozilla.gecko.browserid.BrowserIDKeyPair;
 import org.mozilla.gecko.fxa.login.FxAccountLoginTransition.Transition;
 import org.mozilla.gecko.fxa.login.State.StateLabel;
 
 public class FxAccountLoginStateMachine {
@@ -24,17 +24,17 @@ public class FxAccountLoginStateMachine 
     public void handleFinal(State state);
     public BrowserIDKeyPair generateKeyPair() throws NoSuchAlgorithmException;
   }
 
   public static class ExecuteDelegate {
     protected final LoginStateMachineDelegate delegate;
     protected final StateLabel desiredStateLabel;
     // It's as difficult to detect arbitrary cycles as repeated states.
-    protected final Set<StateLabel> stateLabelsSeen = new HashSet<StateLabel>();
+    protected final Set<StateLabel> stateLabelsSeen = EnumSet.noneOf(StateLabel.class);
 
     protected ExecuteDelegate(StateLabel initialStateLabel, StateLabel desiredStateLabel, LoginStateMachineDelegate delegate) {
       this.delegate = delegate;
       this.desiredStateLabel = desiredStateLabel;
       this.stateLabelsSeen.add(initialStateLabel);
     }
 
     public FxAccountClient getClient() {
--- a/mobile/android/base/fxa/sync/FxAccountGlobalSession.java
+++ b/mobile/android/base/fxa/sync/FxAccountGlobalSession.java
@@ -2,17 +2,19 @@
  * 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.fxa.sync;
 
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.util.Collections;
+import java.util.EnumMap;
 import java.util.HashMap;
+import java.util.Map;
 
 import org.json.simple.parser.ParseException;
 import org.mozilla.gecko.sync.GlobalSession;
 import org.mozilla.gecko.sync.NonObjectJSONException;
 import org.mozilla.gecko.sync.SyncConfiguration;
 import org.mozilla.gecko.sync.SyncConfigurationException;
 import org.mozilla.gecko.sync.delegates.BaseGlobalSessionCallback;
 import org.mozilla.gecko.sync.delegates.ClientsDataDelegate;
@@ -29,14 +31,14 @@ public class FxAccountGlobalSession exte
                                 ClientsDataDelegate clientsDelegate)
                                     throws SyncConfigurationException, IllegalArgumentException, IOException, ParseException, NonObjectJSONException, URISyntaxException {
     super(config, callback, context, clientsDelegate, null);
   }
 
   @Override
   public void prepareStages() {
     super.prepareStages();
-    HashMap<Stage, GlobalSyncStage> stages = new HashMap<Stage, GlobalSyncStage>();
+    Map<Stage, GlobalSyncStage> stages = new EnumMap<>(Stage.class);
     stages.putAll(this.stages);
     stages.put(Stage.ensureClusterURL, new CheckPreconditionsStage());
     this.stages = Collections.unmodifiableMap(stages);
   }
 }
--- a/mobile/android/base/home/RemoteTabsPanel.java
+++ b/mobile/android/base/home/RemoteTabsPanel.java
@@ -1,16 +1,18 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * 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.home;
 
+import java.util.EnumMap;
 import java.util.HashMap;
+import java.util.Map;
 
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.fxa.AccountLoader;
 import org.mozilla.gecko.fxa.FirefoxAccounts;
 import org.mozilla.gecko.fxa.FxAccountConstants;
 import org.mozilla.gecko.fxa.login.State;
 import org.mozilla.gecko.fxa.login.State.Action;
 import org.mozilla.gecko.sync.SyncConstants;
@@ -47,17 +49,17 @@ public class RemoteTabsPanel extends Hom
     // don't want to detach and re-attach panels unnecessarily, because that
     // causes flickering.
     private Fragment mCurrentFragment;
 
     // A lazily-populated cache of fragments corresponding to the possible
     // system account states. We don't want to re-create panels unnecessarily,
     // because that can cause flickering. Be aware that null is a valid key; it
     // corresponds to "no Account, neither Firefox nor Legacy Sync."
-    private final HashMap<Action, Fragment> mFragmentCache = new HashMap<Action, Fragment>();
+    private final Map<Action, Fragment> mFragmentCache = new EnumMap<>(Action.class);
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
         return inflater.inflate(R.layout.home_remote_tabs_panel, container, false);
     }
 
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
--- a/mobile/android/base/sync/GlobalSession.java
+++ b/mobile/android/base/sync/GlobalSession.java
@@ -5,16 +5,17 @@
 package org.mozilla.gecko.sync;
 
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.EnumMap;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicLong;
 
@@ -169,17 +170,17 @@ public class GlobalSession implements Ht
       @Override
       public void executeCommand(final GlobalSession session, List<String> args) {
         CommandProcessor.displayURI(args, session.getContext());
       }
     });
   }
 
   protected void prepareStages() {
-    HashMap<Stage, GlobalSyncStage> stages = new HashMap<Stage, GlobalSyncStage>();
+    Map<Stage, GlobalSyncStage> stages = new EnumMap<Stage, GlobalSyncStage>(Stage.class);
 
     stages.put(Stage.checkPreconditions,      new CheckPreconditionsStage());
     stages.put(Stage.ensureClusterURL,        new EnsureClusterURLStage(nodeAssignmentCallback));
     stages.put(Stage.fetchInfoCollections,    new FetchInfoCollectionsStage());
     stages.put(Stage.fetchMetaGlobal,         new FetchMetaGlobalStage());
     stages.put(Stage.ensureKeysStage,         new EnsureCrypto5KeysStage());
     stages.put(Stage.syncClientsEngine,       new SyncClientsEngineStage());