From a9cdc5b4d77d3b3211ed9567f63ae2ae2111fc46 Mon Sep 17 00:00:00 2001 From: Paul Heinrich Date: Thu, 16 May 2024 15:22:07 +0200 Subject: [PATCH] inline abstract module attributes and get rid of them --- .../matsim/core/controler/AbstractModule.java | 53 +++++++------------ 1 file changed, 20 insertions(+), 33 deletions(-) diff --git a/matsim/src/main/java/org/matsim/core/controler/AbstractModule.java b/matsim/src/main/java/org/matsim/core/controler/AbstractModule.java index d6d3eb94efa..fcf5feeefa8 100644 --- a/matsim/src/main/java/org/matsim/core/controler/AbstractModule.java +++ b/matsim/src/main/java/org/matsim/core/controler/AbstractModule.java @@ -76,25 +76,10 @@ public abstract class AbstractModule implements Module { private Binder binder; - private Multibinder eventHandlerMultibinder; - private Multibinder controlerListenerMultibinder; - - /** - * Contents retrieved (I think) by injected method QSim#addQueueSimulationListeners(...). Is not public, and therefore cannot be referenced from here. - *
- * I think that that method will be called every time the mobsim will be constructed. If the injected classes are singletons, they will - * presumably be re-used, otherwise they will be newly constructed. - */ - private Multibinder mobsimListenerMultibinder; - - private Multibinder snapshotWriterMultibinder; - private MapBinder, AttributeConverter> attributeConverterMapBinder; - private Multibinder qsimModulesMultibinder; @Inject com.google.inject.Injector bootstrapInjector; private Config config; - private Multibinder qsimOverridingModulesMultibinder; public AbstractModule() { // config will be injected later @@ -121,17 +106,13 @@ public final void configure(Binder binder) { private void initializeMultibinders() { // We do need to make these calls here in order to register the multi binders. Otherwise, guice doesn't know, that they exist. In particular, // if none of the corresponding addXXXBinding methods was called, the set binder would not be registered, and guice would complain. - this.mobsimListenerMultibinder = Multibinder.newSetBinder(this.binder, MobsimListener.class); - this.snapshotWriterMultibinder = Multibinder.newSetBinder(this.binder, SnapshotWriter.class); - this.eventHandlerMultibinder = Multibinder.newSetBinder(this.binder, EventHandler.class); - this.controlerListenerMultibinder = Multibinder.newSetBinder(this.binder, ControlerListener.class); - this.attributeConverterMapBinder = - MapBinder.newMapBinder( - this.binder, - new TypeLiteral>(){}, - new TypeLiteral>() {} ); - this.qsimModulesMultibinder = Multibinder.newSetBinder(this.binder, AbstractQSimModule.class); - this.qsimOverridingModulesMultibinder = Multibinder.newSetBinder( this.binder, AbstractQSimModule.class, Names.named( "overridesFromAbstractModule" ) ); + Multibinder.newSetBinder(this.binder, MobsimListener.class); + Multibinder.newSetBinder(this.binder, SnapshotWriter.class); + Multibinder.newSetBinder(this.binder, EventHandler.class); + Multibinder.newSetBinder(this.binder, ControlerListener.class); + MapBinder.newMapBinder(this.binder, new TypeLiteral>(){}, new TypeLiteral>() {} ); + Multibinder.newSetBinder(this.binder, AbstractQSimModule.class); + Multibinder.newSetBinder( this.binder, AbstractQSimModule.class, Names.named( "overridesFromAbstractModule" ) ); } public abstract void install(); @@ -146,21 +127,21 @@ protected final void install(Module module) { } protected final LinkedBindingBuilder addEventHandlerBinding() { - return eventHandlerMultibinder.addBinding(); + return Multibinder.newSetBinder(this.binder, EventHandler.class).addBinding(); } protected final void installQSimModule(AbstractQSimModule qsimModule) { - qsimModulesMultibinder.addBinding().toInstance(qsimModule); + Multibinder.newSetBinder(this.binder, AbstractQSimModule.class).addBinding().toInstance(qsimModule); } protected final void installOverridingQSimModule(AbstractQSimModule qsimModule) { - qsimOverridingModulesMultibinder.addBinding().toInstance(qsimModule); + Multibinder.newSetBinder( this.binder, AbstractQSimModule.class, Names.named( "overridesFromAbstractModule" ) ).addBinding().toInstance(qsimModule); } /** * @see ControlerListener */ protected final LinkedBindingBuilder addControlerListenerBinding() { - return controlerListenerMultibinder.addBinding(); + return Multibinder.newSetBinder(this.binder, ControlerListener.class).addBinding(); } /** @@ -182,16 +163,22 @@ protected final com.google.inject.binder.LinkedBindingBuilder + * I think that that method will be called every time the mobsim will be constructed. If the injected classes are singletons, they will + * presumably be re-used, otherwise they will be newly constructed. + */ protected final com.google.inject.binder.LinkedBindingBuilder addMobsimListenerBinding() { - return mobsimListenerMultibinder.addBinding(); + return Multibinder.newSetBinder(this.binder, MobsimListener.class).addBinding(); } protected final com.google.inject.binder.LinkedBindingBuilder addSnapshotWriterBinding() { - return snapshotWriterMultibinder.addBinding(); + return Multibinder.newSetBinder(this.binder, SnapshotWriter.class).addBinding(); } protected final LinkedBindingBuilder> addAttributeConverterBinding(final Class clazz ) { - return attributeConverterMapBinder.addBinding( clazz ); + return MapBinder.newMapBinder(this.binder, new TypeLiteral>(){}, new TypeLiteral>() {} ).addBinding( clazz ); } /** * @deprecated better use {@link #addTravelDisutilityFactoryBinding(String)}.