• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 package org.chromium.base.test.transit;
6 
7 import org.chromium.base.test.transit.ConditionalState.Phase;
8 
9 import java.util.ArrayList;
10 import java.util.List;
11 
12 /** Keeps track of all existing TransitStations and which one is active. */
13 public class TrafficControl {
14     private static final List<TransitStation> sAllStations = new ArrayList<>();
15 
16     private static TransitStation sActiveStation;
17 
notifyCreatedStation(TransitStation station)18     static void notifyCreatedStation(TransitStation station) {
19         sAllStations.add(station);
20     }
21 
notifyActiveStationChanged(TransitStation newActiveStation)22     static void notifyActiveStationChanged(TransitStation newActiveStation) {
23         assert newActiveStation.getPhase() == Phase.ACTIVE : "New active Station must be ACTIVE";
24         if (sActiveStation != null) {
25             assert sActiveStation.getPhase() != Phase.ACTIVE
26                     : "Previously active station was not ACTIVE";
27         }
28         sActiveStation = newActiveStation;
29     }
30 
getAllStations()31     static List<TransitStation> getAllStations() {
32         return sAllStations;
33     }
34 
getActiveStation()35     static TransitStation getActiveStation() {
36         return sActiveStation;
37     }
38 }
39