MATSIM
ScenarioByInstanceModule.java
Go to the documentation of this file.
1 
2 /* *********************************************************************** *
3  * project: org.matsim.*
4  * ScenarioByInstanceModule.java
5  * *
6  * *********************************************************************** *
7  * *
8  * copyright : (C) 2019 by the members listed in the COPYING, *
9  * LICENSE and WARRANTY file. *
10  * email : info at matsim dot org *
11  * *
12  * *********************************************************************** *
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * See also COPYING, LICENSE and WARRANTY file *
19  * *
20  * *********************************************************************** */
21 
22  package org.matsim.core.scenario;
23 
24 import com.google.inject.Provides;
25 import org.matsim.api.core.v01.Scenario;
32 import org.matsim.lanes.Lanes;
36 
37 import jakarta.inject.Inject;
38 import jakarta.inject.Provider;
39 
40 public final class ScenarioByInstanceModule extends AbstractModule {
41 
42  private final Scenario scenario;
43 
45  this.scenario = scenario;
46  }
47 
48  @Override
49  public void install() {
50  // if no network provided, assume it comes from somewhere else, and this module just provides
51  // the scenario "elements"
52  if ( scenario != null ) bind(Scenario.class).toInstance(scenario);
53  if (getConfig().transit().isUseTransit()) {
54  bind(TransitSchedule.class).toProvider(TransitScheduleProvider.class);
55  bind(Vehicles.class).annotatedWith(Transit.class).toProvider(TransitVehiclesProvider.class);
56  }
57  }
58 
59  @Provides Network provideNetwork(Scenario scenario) {
60  return scenario.getNetwork();
61  }
62 
63  @Provides Population providePopulation(Scenario scenario) {
64  return scenario.getPopulation();
65  }
66 
67  @Provides PopulationFactory providePopulationFactory(Population population) {
68  return population.getFactory();
69  }
70 
71  @Provides ActivityFacilities provideActivityFacilities(Scenario scenario) {
72  return scenario.getActivityFacilities();
73  }
74 
75  @Provides
76  Households provideHouseholds(Scenario scenario) {
77  return scenario.getHouseholds();
78  }
79 
80  @Provides
81  Vehicles provideVehicles(Scenario scenario) {
82  return scenario.getVehicles();
83  }
84 
85  @Provides
86  Lanes provideLanes(Scenario scenario) {
87  return scenario.getLanes();
88  }
89 
90  private static class TransitScheduleProvider implements Provider<TransitSchedule> {
91 
92  @Inject
93  Scenario scenario;
94 
95  @Override
96  public TransitSchedule get() {
97  return scenario.getTransitSchedule();
98  }
99 
100  }
101 
102  private static class TransitVehiclesProvider implements Provider<Vehicles> {
103 
104  @Inject
105  Scenario scenario;
106 
107  @Override
108  public Vehicles get() {
109  return scenario.getTransitVehicles();
110  }
111  }
112 }
ActivityFacilities getActivityFacilities()