Class RealMapBinder<K,V>
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
The BindingSelection contains some of the core state and logic for the MapBinder.private static final class
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 final class
BindsMap<K, Set<V>>
and {Map<K, Set<Provider<V>>>
.(package private) static final class
A factory for aMap.Entry<K, Provider<V>>
.private static class
A base class for ProviderWithDependencies that need equality based on a specific object.private static final class
private static class
A base class for ProviderWithDependencies that need equality based on a specific object.private static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Binder
private final RealMapBinder.BindingSelection<K,
V> private final RealMultibinder<Map.Entry<K,
Provider<V>>> private static final com.google.common.collect.ImmutableSet<Dependency<?>>
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
RealMapBinder
(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Key<Map<K, V>> mapKey, RealMultibinder<Map.Entry<K, Provider<V>>> entrySetBinder) -
Method Summary
Modifier and TypeMethodDescriptionaddBinding
(K key) This creates two bindings.void
Contributes bindings and other configurations for this module tobinder
.private static <K,
V> InternalProvisionException createNullValueException
(K key, Binding<V> binding) (package private) static <K,
V> TypeLiteral<Map.Entry<K, Provider<V>>> entryOfJavaxProviderOf
(TypeLiteral<K> keyType, TypeLiteral<V> valueType) (package private) static <K,
V> TypeLiteral<Map.Entry<K, Provider<V>>> entryOfProviderOf
(TypeLiteral<K> keyType, TypeLiteral<V> valueType) boolean
getKeyForNewValue
(K key) Adds a binding to the map for the given key.getKeyOfProvider
(Key<T> valueKey) Given a Keywill return a Key<Provider > int
hashCode()
(package private) static <K,
V> TypeLiteral<Map<K, V>> mapOf
(TypeLiteral<K> keyType, TypeLiteral<V> valueType) (package private) static <K,
V> TypeLiteral<Map<K, Collection<javax.inject.Provider<V>>>> mapOfCollectionOfJavaxProviderOf
(TypeLiteral<K> keyType, TypeLiteral<V> valueType) (package private) static <K,
V> TypeLiteral<Map<K, Collection<Provider<V>>>> mapOfCollectionOfProviderOf
(TypeLiteral<K> keyType, TypeLiteral<V> valueType) (package private) static <K,
V> TypeLiteral<Map<K, javax.inject.Provider<V>>> mapOfJavaxProviderOf
(TypeLiteral<K> keyType, TypeLiteral<V> valueType) (package private) static <K,
V> TypeLiteral<Map<K, Provider<V>>> mapOfProviderOf
(TypeLiteral<K> keyType, TypeLiteral<V> valueType) (package private) static <K,
V> TypeLiteral<Map<K, Set<javax.inject.Provider<V>>>> mapOfSetOfJavaxProviderOf
(TypeLiteral<K> keyType, TypeLiteral<V> valueType) (package private) static <K,
V> TypeLiteral<Map<K, 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 ofkeyType
/valueType
in aMap
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) private static <K,
V> RealMapBinder<K, V> newRealMapBinder
(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Key<Map<K, V>> mapKey, RealMultibinder<Map.Entry<K, Provider<V>>> entrySetBinder) static <K,
V> RealMapBinder<K, V> newRealMapBinder
(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Annotation annotation) Returns a new mapbinder that collects entries ofkeyType
/valueType
in aMap
that is itself bound withannotation
.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 ofkeyType
/valueType
in aMap
that is itself bound withannotationType
.void
(package private) static <K,
V> TypeLiteral<Set<Map.Entry<K, javax.inject.Provider<V>>>> setOfEntryOfJavaxProviderOf
(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
-
Field Details
-
MODULE_DEPENDENCIES
-
bindingSelection
-
binder
-
entrySetBinder
-
-
Constructor Details
-
RealMapBinder
private RealMapBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Key<Map<K, V>> mapKey, RealMultibinder<Map.Entry<K, Provider<V>>> entrySetBinder)
-
-
Method Details
-
newMapRealBinder
public static <K,V> RealMapBinder<K,V> newMapRealBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType) Returns a new mapbinder that collects entries ofkeyType
/valueType
in aMap
that is itself bound with no binding annotation. -
newRealMapBinder
public static <K,V> RealMapBinder<K,V> newRealMapBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Annotation annotation) Returns a new mapbinder that collects entries ofkeyType
/valueType
in aMap
that is itself bound withannotation
. -
newRealMapBinder
public 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 ofkeyType
/valueType
in aMap
that is itself bound withannotationType
. -
mapOf
-
mapOfProviderOf
static <K,V> TypeLiteral<Map<K,Provider<V>>> mapOfProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType) -
mapOfJavaxProviderOf
static <K,V> TypeLiteral<Map<K,javax.inject.Provider<V>>> mapOfJavaxProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType) -
mapOfSetOfProviderOf
static <K,V> TypeLiteral<Map<K,Set<Provider<V>>>> mapOfSetOfProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType) -
mapOfSetOfJavaxProviderOf
static <K,V> TypeLiteral<Map<K,Set<javax.inject.Provider<V>>>> mapOfSetOfJavaxProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType) -
mapOfCollectionOfProviderOf
static <K,V> TypeLiteral<Map<K,Collection<Provider<V>>>> mapOfCollectionOfProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType) -
mapOfCollectionOfJavaxProviderOf
static <K,V> TypeLiteral<Map<K,Collection<javax.inject.Provider<V>>>> mapOfCollectionOfJavaxProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType) -
entryOfProviderOf
static <K,V> TypeLiteral<Map.Entry<K,Provider<V>>> entryOfProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType) -
entryOfJavaxProviderOf
static <K,V> TypeLiteral<Map.Entry<K,Provider<V>>> entryOfJavaxProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType) -
setOfEntryOfJavaxProviderOf
static <K,V> TypeLiteral<Set<Map.Entry<K,javax.inject.Provider<V>>>> setOfEntryOfJavaxProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType) -
getKeyOfProvider
Given a Keywill return a Key<Provider > -
newRealMapBinder
static <K,V> RealMapBinder<K,V> newRealMapBinder(Binder binder, TypeLiteral<K> keyType, Key<V> valueTypeAndAnnotation) -
newRealMapBinder
private static <K,V> RealMapBinder<K,V> newRealMapBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Key<Map<K, V>> mapKey, RealMultibinder<Map.Entry<K, Provider<V>>> entrySetBinder) -
permitDuplicates
public void permitDuplicates() -
getKeyForNewValue
Adds a binding to the map for the given key. -
addBinding
This creates two bindings. One for theMap.Entry<K, Provider<V>>
and another forV
. -
configure
Description copied from interface:Module
Contributes 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 methods
are discovered. -
equals
-
hashCode
public int hashCode() -
createNullValueException
private static <K,V> InternalProvisionException createNullValueException(K key, Binding<V> binding)
-