public final class RealMapBinder<K,V> extends Object 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.
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.
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(Object o) |
int |
hashCode() |
static <K,V> RealMapBinder<K,V> |
newMapRealBinder(Binder binder,
TypeLiteral<K> keyType,
TypeLiteral<V> valueType)
Returns a new mapbinder that collects entries of
keyType /valueType in a Map that is itself bound with no binding annotation. |
static <K,V> RealMapBinder<K,V> |
newRealMapBinder(Binder binder,
TypeLiteral<K> keyType,
TypeLiteral<V> valueType,
Annotation annotation)
Returns a new mapbinder that collects entries of
keyType /valueType in a Map that is itself bound with annotation . |
static <K,V> RealMapBinder<K,V> |
newRealMapBinder(Binder binder,
TypeLiteral<K> keyType,
TypeLiteral<V> valueType,
Class<? extends Annotation> annotationType)
Returns a new mapbinder that collects entries of
keyType /valueType in a Map that is itself bound with annotationType . |
void |
permitDuplicates() |
public static <K,V> RealMapBinder<K,V> newMapRealBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType)
keyType
/valueType
in a Map
that is itself bound with no binding annotation.public static <K,V> RealMapBinder<K,V> newRealMapBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Annotation annotation)
keyType
/valueType
in a Map
that is itself bound with annotation
.public static <K,V> RealMapBinder<K,V> newRealMapBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Class<? extends Annotation> annotationType)
keyType
/valueType
in a Map
that is itself bound with annotationType
.public void permitDuplicates()
public LinkedBindingBuilder<V> addBinding(K key)
Map.Entry<K, Provider<V>>
and another for 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.
Copyright © 2006–2018 Google, Inc.. All rights reserved.