-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update injection structure (#294)
* clean up overrdides, merge into configurator * streamline configurator * unify injection * enforce use of a custom EqasimConfigurator * define default configurator via properties * clarify error
- Loading branch information
Showing
55 changed files
with
425 additions
and
497 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
38 changes: 9 additions & 29 deletions
38
core/src/main/java/org/eqasim/core/misc/InjectorBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,34 @@ | ||
package org.eqasim.core.misc; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.eqasim.core.simulation.EqasimConfigurator; | ||
import org.matsim.api.core.v01.Scenario; | ||
import org.matsim.core.controler.AbstractModule; | ||
import org.matsim.core.controler.Injector; | ||
import org.matsim.core.events.EventsManagerModule; | ||
import org.matsim.core.router.TripRouterModule; | ||
import org.matsim.core.router.costcalculators.TravelDisutilityModule; | ||
import org.matsim.core.scenario.ScenarioByInstanceModule; | ||
import org.matsim.core.scoring.functions.CharyparNagelScoringFunctionModule; | ||
import org.matsim.core.trafficmonitoring.TravelTimeCalculatorModule; | ||
import org.matsim.core.controler.Controler; | ||
|
||
public class InjectorBuilder { | ||
private final Scenario scenario; | ||
private AbstractModule module = AbstractModule.emptyModule(); // new ControlerDefaultsModule(); | ||
private final Controler controller; | ||
|
||
public InjectorBuilder(Scenario scenario) { | ||
this.scenario = scenario; | ||
public InjectorBuilder(Scenario scenario, EqasimConfigurator configurator) { | ||
this.controller = new Controler(scenario); | ||
configurator.configureController(controller); | ||
} | ||
|
||
public InjectorBuilder addOverridingModule(AbstractModule module) { | ||
this.module = AbstractModule.override(Collections.singleton(this.module), module); | ||
controller.addOverridingModule(module); | ||
return this; | ||
} | ||
|
||
public InjectorBuilder addOverridingModules(List<AbstractModule> modules) { | ||
for (AbstractModule module : modules) { | ||
addOverridingModule(module); | ||
controller.addOverridingModule(module); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
public com.google.inject.Injector build() { | ||
AbstractModule standardModule = new AbstractModule() { | ||
@Override | ||
public void install() { | ||
install(new EventsManagerModule()); | ||
install(new TripRouterModule()); | ||
install(new CharyparNagelScoringFunctionModule()); | ||
install(new TravelDisutilityModule()); | ||
install(new TravelTimeCalculatorModule()); | ||
} | ||
}; | ||
|
||
return Injector.createInjector( // | ||
scenario.getConfig(), // | ||
new ScenarioByInstanceModule(scenario), // | ||
AbstractModule.override(Collections.singleton(standardModule), module)); | ||
return controller.getInjector(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.