Class MapBinder.RealMapBinder<K,V>
- java.lang.Object
-
- org.elasticsearch.common.inject.multibindings.MapBinder<K,V>
-
- org.elasticsearch.common.inject.multibindings.MapBinder.RealMapBinder<K,V>
-
- All Implemented Interfaces:
Module
public static final class MapBinder.RealMapBinder<K,V> extends MapBinder<K,V> implements Module
The actual mapbinder plays several roles:As a MapBinder, it acts as a factory for LinkedBindingBuilders for each of the map's values. It delegates to a
Multibinderof entries (keys to value providers).As a Module, it installs the binding to the map itself, as well as to a corresponding map whose values are providers. It uses the entry set multibinder to construct the map and the provider map.
As a module, this implements equals() and hashcode() in order to trick Guice into executing its configure() method only once. That makes it so that multiple mapbinders can be created for the same target map, but only one is bound. Since the list of bindings is retrieved from the injector itself (and not the mapbinder), each mapbinder has access to all contributions from all equivalent mapbinders.
Rather than binding a single Map.Entry<K, V>, the map binder binds keys and values independently. This allows the values to be properly scoped.
We use a subclass to hide 'implements Module' from the public API.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMapBinder.RealMapBinder.MapBinderProviderWithDependencies<K,V>-
Nested classes/interfaces inherited from class org.elasticsearch.common.inject.multibindings.MapBinder
MapBinder.RealMapBinder<K,V>
-
-
Method Summary
Modifier and Type Method Description LinkedBindingBuilder<V>addBinding(K key)This creates two bindings.voidconfigure(Binder binder)Contributes bindings and other configurations for this module tobinder.booleanequals(java.lang.Object o)inthashCode()-
Methods inherited from class org.elasticsearch.common.inject.multibindings.MapBinder
newMapBinder, newMapBinder, newMapBinder, newMapBinder, newMapBinder, newMapBinder
-
-
-
-
Method Detail
-
addBinding
public LinkedBindingBuilder<V> addBinding(K key)
This creates two bindings. One for theMap.Entry<K, Provider<V>>and another forV.- Specified by:
addBindingin classMapBinder<K,V>
-
configure
public void configure(Binder binder)
Description copied from interface:ModuleContributes bindings and other configurations for this module tobinder.Do not invoke this method directly to install submodules. Instead use
Binder.install(Module), which ensures thatprovider methodsare discovered.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-