public final class RealMapBinder<K,V> extends java.lang.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 | Class and Description |
---|---|
private static class |
RealMapBinder.BindingSelection<K,V>
The BindingSelection contains some of the core state and logic for the MapBinder.
|
private static class |
RealMapBinder.ExtensionRealMapProvider<K,V>
Implementation of a provider instance for the map that also exposes details about the MapBinder
using the extension SPI, delegating to another provider instance for non-extension (e.g, the
actual provider instance info) data.
|
private static class |
RealMapBinder.MultimapBinder<K,V>
Binds
Map<K, Set<V>> and {Map<K, Set<Provider<V>>> . |
(package private) static class |
RealMapBinder.ProviderMapEntry<K,V>
A factory for a
Map.Entry<K, Provider<V>> . |
private static class |
RealMapBinder.RealMapBinderProviderWithDependencies<K,V,P>
A base class for ProviderWithDependencies that need equality based on a specific object.
|
private static class |
RealMapBinder.RealMapProvider<K,V> |
private static class |
RealMapBinder.RealMultimapBinderProviderWithDependencies<K,V,P>
A base class for ProviderWithDependencies that need equality based on a specific object.
|
private static class |
RealMapBinder.RealProviderMapProvider<K,V> |
Modifier and Type | Field and Description |
---|---|
private Binder |
binder |
private RealMapBinder.BindingSelection<K,V> |
bindingSelection |
private RealMultibinder<java.util.Map.Entry<K,Provider<V>>> |
entrySetBinder |
private static com.google.common.collect.ImmutableSet<Dependency<?>> |
MODULE_DEPENDENCIES |
Modifier | Constructor and Description |
---|---|
private |
RealMapBinder(Binder binder,
TypeLiteral<K> keyType,
TypeLiteral<V> valueType,
Key<java.util.Map<K,V>> mapKey,
RealMultibinder<java.util.Map.Entry<K,Provider<V>>> entrySetBinder) |
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 . |
private static <K,V> InternalProvisionException |
createNullValueException(K key,
Binding<V> binding) |
(package private) static <K,V> TypeLiteral<java.util.Map.Entry<K,Provider<V>>> |
entryOfJavaxProviderOf(TypeLiteral<K> keyType,
TypeLiteral<V> valueType) |
(package private) static <K,V> TypeLiteral<java.util.Map.Entry<K,Provider<V>>> |
entryOfProviderOf(TypeLiteral<K> keyType,
TypeLiteral<V> valueType) |
boolean |
equals(java.lang.Object o) |
(package private) Key<V> |
getKeyForNewValue(K key)
Adds a binding to the map for the given key.
|
private static <T> Key<Provider<T>> |
getKeyOfProvider(Key<T> valueKey)
Given a Key
|
int |
hashCode() |
(package private) static <K,V> TypeLiteral<java.util.Map<K,V>> |
mapOf(TypeLiteral<K> keyType,
TypeLiteral<V> valueType) |
(package private) static <K,V> TypeLiteral<java.util.Map<K,java.util.Collection<javax.inject.Provider<V>>>> |
mapOfCollectionOfJavaxProviderOf(TypeLiteral<K> keyType,
TypeLiteral<V> valueType) |
(package private) static <K,V> TypeLiteral<java.util.Map<K,java.util.Collection<Provider<V>>>> |
mapOfCollectionOfProviderOf(TypeLiteral<K> keyType,
TypeLiteral<V> valueType) |
(package private) static <K,V> TypeLiteral<java.util.Map<K,javax.inject.Provider<V>>> |
mapOfJavaxProviderOf(TypeLiteral<K> keyType,
TypeLiteral<V> valueType) |
(package private) static <K,V> TypeLiteral<java.util.Map<K,Provider<V>>> |
mapOfProviderOf(TypeLiteral<K> keyType,
TypeLiteral<V> valueType) |
(package private) static <K,V> TypeLiteral<java.util.Map<K,java.util.Set<javax.inject.Provider<V>>>> |
mapOfSetOfJavaxProviderOf(TypeLiteral<K> keyType,
TypeLiteral<V> valueType) |
(package private) static <K,V> TypeLiteral<java.util.Map<K,java.util.Set<Provider<V>>>> |
mapOfSetOfProviderOf(TypeLiteral<K> keyType,
TypeLiteral<V> valueType) |
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. |
(package private) static <K,V> RealMapBinder<K,V> |
newRealMapBinder(Binder binder,
TypeLiteral<K> keyType,
Key<V> valueTypeAndAnnotation) |
static <K,V> RealMapBinder<K,V> |
newRealMapBinder(Binder binder,
TypeLiteral<K> keyType,
TypeLiteral<V> valueType,
java.lang.annotation.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,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns a new mapbinder that collects entries of
keyType /valueType in a Map that is itself bound with annotationType . |
private static <K,V> RealMapBinder<K,V> |
newRealMapBinder(Binder binder,
TypeLiteral<K> keyType,
TypeLiteral<V> valueType,
Key<java.util.Map<K,V>> mapKey,
RealMultibinder<java.util.Map.Entry<K,Provider<V>>> entrySetBinder) |
void |
permitDuplicates() |
(package private) static <K,V> TypeLiteral<java.util.Set<java.util.Map.Entry<K,javax.inject.Provider<V>>>> |
setOfEntryOfJavaxProviderOf(TypeLiteral<K> keyType,
TypeLiteral<V> valueType) |
private static final com.google.common.collect.ImmutableSet<Dependency<?>> MODULE_DEPENDENCIES
private final RealMapBinder.BindingSelection<K,V> bindingSelection
private final Binder binder
private final RealMultibinder<java.util.Map.Entry<K,Provider<V>>> entrySetBinder
private RealMapBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Key<java.util.Map<K,V>> mapKey, RealMultibinder<java.util.Map.Entry<K,Provider<V>>> entrySetBinder)
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, java.lang.annotation.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, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
keyType
/valueType
in a Map
that is itself bound with annotationType
.static <K,V> TypeLiteral<java.util.Map<K,V>> mapOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
static <K,V> TypeLiteral<java.util.Map<K,Provider<V>>> mapOfProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
static <K,V> TypeLiteral<java.util.Map<K,javax.inject.Provider<V>>> mapOfJavaxProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
static <K,V> TypeLiteral<java.util.Map<K,java.util.Set<Provider<V>>>> mapOfSetOfProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
static <K,V> TypeLiteral<java.util.Map<K,java.util.Set<javax.inject.Provider<V>>>> mapOfSetOfJavaxProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
static <K,V> TypeLiteral<java.util.Map<K,java.util.Collection<Provider<V>>>> mapOfCollectionOfProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
static <K,V> TypeLiteral<java.util.Map<K,java.util.Collection<javax.inject.Provider<V>>>> mapOfCollectionOfJavaxProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
static <K,V> TypeLiteral<java.util.Map.Entry<K,Provider<V>>> entryOfProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
static <K,V> TypeLiteral<java.util.Map.Entry<K,Provider<V>>> entryOfJavaxProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
static <K,V> TypeLiteral<java.util.Set<java.util.Map.Entry<K,javax.inject.Provider<V>>>> setOfEntryOfJavaxProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
private static <T> Key<Provider<T>> getKeyOfProvider(Key<T> valueKey)
static <K,V> RealMapBinder<K,V> newRealMapBinder(Binder binder, TypeLiteral<K> keyType, Key<V> valueTypeAndAnnotation)
private static <K,V> RealMapBinder<K,V> newRealMapBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Key<java.util.Map<K,V>> mapKey, RealMultibinder<java.util.Map.Entry<K,Provider<V>>> entrySetBinder)
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.
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
private static <K,V> InternalProvisionException createNullValueException(K key, Binding<V> binding)