MATSIM
QSimModule.java
Go to the documentation of this file.
1 
2 /* *********************************************************************** *
3  * project: org.matsim.*
4  * QSimModule.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.mobsim.qsim;
23 
24 
25 import java.util.Arrays;
26 import java.util.Collection;
27 import java.util.Collections;
28 import java.util.List;
29 import java.util.Set;
30 
38 
39 import com.google.inject.Key;
40 import com.google.inject.TypeLiteral;
41 import com.google.inject.name.Names;
42 
66 public final class QSimModule extends AbstractModule {
67  private final boolean addDefaultQSimModules;
68 
69  public QSimModule() {
70  this(true);
71  }
72 
73  public QSimModule(boolean addDefaultQSimModules) {
74  this.addDefaultQSimModules = addDefaultQSimModules;
75  }
76 
77  @Override
78  public void install() {
80  // this is essentially a structured collection of strings that determines which QSimModules will later be used. Can be
81  // used to configure from config, but maybe easiest just ignore when getting started with this. The default QSimModules
82  // bind the corresponding implementations under the correct names.
83 
84  if (addDefaultQSimModules) {
85  getDefaultQSimModules().forEach(this::installQSimModule);
86  // this binds all the default modules, i.e. sets up the default QSim
87  }
88 
89  bind(
90  Key.get(new TypeLiteral<List<AbstractQSimModule>>() {}, Names.named("overrides"))
91  ).toInstance(Collections.emptyList());
92  // this initializes (I think) the container with the overriding bindings with an empty container. Recall that "Key" and
93  // "TypeLiteral" are only there to circumvent Java type erasure, so what we really have is
94  // List<AbstractQSimModule> annotated with "overrides"
95 
96  bind( new TypeLiteral<Collection<AbstractQSimModule>>() {} ).to(new TypeLiteral<Set<AbstractQSimModule>>() {});
97  // I think that the result of this that you can use @Inject Collection<AbstractQSimModule> in addition to @Inject
98  // Set<AbstractQSimModule>. Don't know why this is needed. kai, jun'23
99 
100  bind(Mobsim.class).toProvider(QSimProvider.class);
101  }
102 
103  static public Collection<AbstractQSimModule> getDefaultQSimModules() {
104  return Arrays.asList(
105  new MessageQueueModule(), // defines "MessageQueueEngine"
106  new ActivityEngineModule(), // defines "ActivityEngine"
107  new QNetsimEngineModule(), // defines "NetsimEngine"
108  new TeleportationModule(), // etc.
109  new PopulationModule(),
111  new TransitEngineModule()
112  );
113  }
114 }
static Collection< AbstractQSimModule > getDefaultQSimModules()
QSimModule(boolean addDefaultQSimModules)
Definition: QSimModule.java:73