Class RealMapBinder<K,V>
- java.lang.Object
-
- com.google.inject.internal.RealMapBinder<K,V>
-
- All Implemented Interfaces:
Module
public final class RealMapBinder<K,V> extends java.lang.Object 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.
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 Classes Modifier and Type Class Description private static classRealMapBinder.BindingSelection<K,V>The BindingSelection contains some of the core state and logic for the MapBinder.private static classRealMapBinder.MultimapBinder<K,V>BindsMap<K, Set<V>>and {Map<K, Set<Provider<V>>>.(package private) static classRealMapBinder.ProviderMapEntry<K,V>A factory for aMap.Entry<K, Provider<V>>.private static classRealMapBinder.RealMapBinderProviderWithDependencies<K,V,P>A base class for ProviderWithDependencies that need equality based on a specific object.private static classRealMapBinder.RealMapProvider<K,V>private static classRealMapBinder.RealMultimapBinderProviderWithDependencies<K,V,P>A base class for ProviderWithDependencies that need equality based on a specific object.private static classRealMapBinder.RealProviderMapProvider<K,V>
-
Field Summary
Fields Modifier and Type Field Description private Binderbinderprivate RealMapBinder.BindingSelection<K,V>bindingSelectionprivate RealMultibinder<java.util.Map.Entry<K,Provider<V>>>entrySetBinderprivate static com.google.common.collect.ImmutableSet<Dependency<?>>MODULE_DEPENDENCIES
-
Constructor Summary
Constructors Modifier Constructor Description privateRealMapBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Key<java.util.Map<K,V>> mapKey, RealMultibinder<java.util.Map.Entry<K,Provider<V>>> entrySetBinder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods 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.private static <K,V>
InternalProvisionExceptioncreateNullValueException(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)booleanequals(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 Keywill return a Key > inthashCode()(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 ofkeyType/valueTypein aMapthat 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<java.util.Map<K,V>> mapKey, RealMultibinder<java.util.Map.Entry<K,Provider<V>>> entrySetBinder)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 ofkeyType/valueTypein aMapthat is itself bound withannotation.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 ofkeyType/valueTypein aMapthat is itself bound withannotationType.voidpermitDuplicates()(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)
-
-
-
Field Detail
-
MODULE_DEPENDENCIES
private static final com.google.common.collect.ImmutableSet<Dependency<?>> MODULE_DEPENDENCIES
-
bindingSelection
private final RealMapBinder.BindingSelection<K,V> bindingSelection
-
binder
private final Binder binder
-
entrySetBinder
private final RealMultibinder<java.util.Map.Entry<K,Provider<V>>> entrySetBinder
-
-
Constructor Detail
-
RealMapBinder
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)
-
-
Method Detail
-
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/valueTypein aMapthat is itself bound with no binding annotation.
-
newRealMapBinder
public 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 ofkeyType/valueTypein aMapthat is itself bound withannotation.
-
newRealMapBinder
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)
Returns a new mapbinder that collects entries ofkeyType/valueTypein aMapthat is itself bound withannotationType.
-
mapOf
static <K,V> TypeLiteral<java.util.Map<K,V>> mapOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
-
mapOfProviderOf
static <K,V> TypeLiteral<java.util.Map<K,Provider<V>>> mapOfProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
-
mapOfJavaxProviderOf
static <K,V> TypeLiteral<java.util.Map<K,javax.inject.Provider<V>>> mapOfJavaxProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
-
mapOfSetOfProviderOf
static <K,V> TypeLiteral<java.util.Map<K,java.util.Set<Provider<V>>>> mapOfSetOfProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
-
mapOfSetOfJavaxProviderOf
static <K,V> TypeLiteral<java.util.Map<K,java.util.Set<javax.inject.Provider<V>>>> mapOfSetOfJavaxProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
-
mapOfCollectionOfProviderOf
static <K,V> TypeLiteral<java.util.Map<K,java.util.Collection<Provider<V>>>> mapOfCollectionOfProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
-
mapOfCollectionOfJavaxProviderOf
static <K,V> TypeLiteral<java.util.Map<K,java.util.Collection<javax.inject.Provider<V>>>> mapOfCollectionOfJavaxProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
-
entryOfProviderOf
static <K,V> TypeLiteral<java.util.Map.Entry<K,Provider<V>>> entryOfProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
-
entryOfJavaxProviderOf
static <K,V> TypeLiteral<java.util.Map.Entry<K,Provider<V>>> entryOfJavaxProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
-
setOfEntryOfJavaxProviderOf
static <K,V> TypeLiteral<java.util.Set<java.util.Map.Entry<K,javax.inject.Provider<V>>>> setOfEntryOfJavaxProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)
-
getKeyOfProvider
private static <T> Key<Provider<T>> getKeyOfProvider(Key<T> valueKey)
Given a Keywill return a Key >
-
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<java.util.Map<K,V>> mapKey, RealMultibinder<java.util.Map.Entry<K,Provider<V>>> entrySetBinder)
-
permitDuplicates
public void permitDuplicates()
-
addBinding
public LinkedBindingBuilder<V> addBinding(K key)
This creates two bindings. One for theMap.Entry<K, Provider<V>>and another forV.
-
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
-
createNullValueException
private static <K,V> InternalProvisionException createNullValueException(K key, Binding<V> binding)
-
-