public static final class MapBinder.RealMapBinder<K,V> extends MapBinder<K,V> implements Module
As a MapBinder, it acts as a factory for LinkedBindingBuilders for
each of the map's values. It delegates to a Multibinder
of
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.
Modifier and Type | Class and Description |
---|---|
static class |
MapBinder.RealMapBinder.MapBinderProviderWithDependencies<K,V> |
MapBinder.RealMapBinder<K,V>
Modifier and Type | Method and Description |
---|---|
LinkedBindingBuilder<V> |
addBinding(K key)
This creates two bindings.
|
void |
configure(Binder binder)
Contributes bindings and other configurations for this module to
binder . |
boolean |
equals(java.lang.Object o) |
int |
hashCode() |
newMapBinder, newMapBinder, newMapBinder, newMapBinder, newMapBinder, newMapBinder
public LinkedBindingBuilder<V> addBinding(K key)
Map.Entry<K, Provider<V>>
and another for V
.addBinding
in class MapBinder<K,V>
public void configure(Binder binder)
Module
binder
.
Do not invoke this method directly to install submodules. Instead use
Binder.install(Module)
, which ensures that provider methods
are
discovered.
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object