Class RealMapBinder.RealMapProvider<K,V>
- All Implemented Interfaces:
InternalFactory<Map<K,,V>> MapBinderBinding<Map<K,,V>> Provider<Map<K,,V>> HasDependencies,ProviderWithExtensionVisitor<Map<K,,V>> javax.inject.Provider<Map<K,V>>
- Enclosing class:
- RealMapBinder<K,
V>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Set<Dependency<?>>private SingleParameterInjector<V>[]An array of all the injectors.private K[]Fields inherited from class com.google.inject.internal.RealMapBinder.RealMapBinderProviderWithDependencies
bindingSelectionFields inherited from class com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory
provisionCallback -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateRealMapProvider(RealMapBinder.BindingSelection<K, V> bindingSelection) -
Method Summary
Modifier and TypeMethodDescription<B,W> W acceptExtensionVisitor(BindingTargetVisitor<B, W> visitor, ProviderInstanceBinding<? extends B> binding) Instructs the extension determine if the visitor is an instance of a custom extension visitor, and if so, visit it using that method.booleancontainsElement(Element element) Returns true if this MapBinder contains the given Element in order to build the map or uses the given Element in order to support building and injecting the map.protected voiddoInitialize(InjectorImpl injector, Errors errors) Initialize the factory.doProvision(InternalContext context, Dependency<?> dependency) Creates an object to be injected.Returns the keys of other bindings that represent this map.private RealMapBinder.BindingSelection<K,V> Set<Dependency<?>>Returns the known dependencies for this type.Returns all entries in the Map.getEntries(Iterable<? extends Element> elements) Similar toMapBinderBinding.getEntries(), but can be used on a MapBinderBinding retrieved fromElements.getElements(com.google.inject.Module...).Returns the TypeLiteral describing the keys of the map.Returns theKeyfor the map.Returns the TypeLiteral describing the values of the map.booleanReturns true if the MapBinder permits duplicates.Methods inherited from class com.google.inject.internal.RealMapBinder.RealMapBinderProviderWithDependencies
equals, hashCode, initializeMethods inherited from class com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory
get, get, getSource
-
Field Details
-
dependencies
-
injectors
An array of all the injectors.This is parallel to array of keys below
-
keys
-
-
Constructor Details
-
RealMapProvider
-
-
Method Details
-
getBindingSelection
-
doInitialize
Description copied from class:RealMapBinder.RealMapBinderProviderWithDependenciesInitialize the factory. BindingSelection is guaranteed to be initialized at this point and this will be called prior to any provisioning.- Specified by:
doInitializein classRealMapBinder.RealMapBinderProviderWithDependencies<K,V, Map<K, V>> - Throws:
ErrorsException
-
doProvision
protected Map<K,V> doProvision(InternalContext context, Dependency<?> dependency) throws InternalProvisionException Description copied from class:InternalProviderInstanceBindingImpl.FactoryCreates an object to be injected.- Specified by:
doProvisionin classInternalProviderInstanceBindingImpl.Factory<Map<K,V>> - Returns:
- instance to be injected
- Throws:
InternalProvisionException- if a value cannot be provided
-
getDependencies
Description copied from interface:HasDependenciesReturns the known dependencies for this type. If this has dependencies whose values are not known statically, a dependency for theInjectorwill be included in the returned set.- Specified by:
getDependenciesin interfaceHasDependencies- Returns:
- a possibly empty set
-
acceptExtensionVisitor
public <B,W> W acceptExtensionVisitor(BindingTargetVisitor<B, W> visitor, ProviderInstanceBinding<? extends B> binding) Description copied from interface:ProviderWithExtensionVisitorInstructs the extension determine if the visitor is an instance of a custom extension visitor, and if so, visit it using that method. If the visitor is not an instance of the custom extension visitor, this method MUST call visitor.visit(binding).Due to issues with generics, the type parameters of this method do not relate to the type of the provider. In practice, the 'B' type will always be a supertype of 'T'.
- Specified by:
acceptExtensionVisitorin interfaceProviderWithExtensionVisitor<K>
-
getMapKey
Description copied from interface:MapBinderBindingReturns theKeyfor the map.- Specified by:
getMapKeyin interfaceMapBinderBinding<K>
-
getAlternateMapKeys
Description copied from interface:MapBinderBindingReturns the keys of other bindings that represent this map. This will return an entry forMap<K, com.google.inject.Provider<V>>,Map<K, javax.inject.Provider<V>>,Map<K, Set<com.google.inject.Provider<V>>>,Map<K, Set<javax.inject.Provider<V>>>,Map<K, Collection<com.google.inject.Provider<V>>>,Map<K, Collection<javax.inject.Provider<V>>>, andMap<K, Set<V>.- Specified by:
getAlternateMapKeysin interfaceMapBinderBinding<K>
-
getKeyTypeLiteral
Description copied from interface:MapBinderBindingReturns the TypeLiteral describing the keys of the map.The TypeLiteral will always match the type Map's generic type. For example, if getMapKey returns a key of
Map<String, Snack>, then this will always return aTypeLiteral<String>.- Specified by:
getKeyTypeLiteralin interfaceMapBinderBinding<K>
-
getValueTypeLiteral
Description copied from interface:MapBinderBindingReturns the TypeLiteral describing the values of the map.The TypeLiteral will always match the type Map's generic type. For example, if getMapKey returns a key of
Map<String, Snack>, then this will always return aTypeLiteral<Snack>.- Specified by:
getValueTypeLiteralin interfaceMapBinderBinding<K>
-
getEntries
Description copied from interface:MapBinderBindingReturns all entries in the Map. The returned list of Map.Entries contains the key and a binding to the value. Duplicate keys or values will exist as separate Map.Entries in the returned list. This is only supported on bindings returned from an injector. This will throwUnsupportedOperationExceptionif it is called on an element retrieved fromElements.getElements(com.google.inject.Module...).The elements will always match the type Map's generic type. For example, if getMapKey returns a key of
Map<String, Snack>, then this will always return a list of typeList<Map.Entry<String, Binding<Snack>>>.- Specified by:
getEntriesin interfaceMapBinderBinding<K>
-
getEntries
Description copied from interface:MapBinderBindingSimilar toMapBinderBinding.getEntries(), but can be used on a MapBinderBinding retrieved fromElements.getElements(com.google.inject.Module...).One way to use this is to pass in the results of
Elements.getElements(com.google.inject.Module...)as theelementsparameter.This differs from
MapBinderBinding.getEntries()in that it will return duplicates if they are present in theelementspassed in. This does not run the normal Guice de-duplication thatMapBinderBinding.getEntries()does.- Specified by:
getEntriesin interfaceMapBinderBinding<K>
-
permitsDuplicates
public boolean permitsDuplicates()Description copied from interface:MapBinderBindingReturns true if the MapBinder permits duplicates. This is only supported on bindings returned from an injector. This will throwUnsupportedOperationExceptionif it is called on a MapBinderBinding retrieved fromElements.getElements(com.google.inject.Module...).- Specified by:
permitsDuplicatesin interfaceMapBinderBinding<K>
-
containsElement
Description copied from interface:MapBinderBindingReturns true if this MapBinder contains the given Element in order to build the map or uses the given Element in order to support building and injecting the map. This will work for MapBinderBindings retrieved from an injector andElements.getElements(com.google.inject.Module...). Usually this is only necessary if you are working with elements retrieved from modules (without an Injector), otherwiseMapBinderBinding.getEntries()andMapBinderBinding.permitsDuplicates()are better options.If you need to introspect the details of the map, such as the keys, values or if it permits duplicates, it is necessary to pass the elements through an Injector and use
MapBinderBinding.getEntries()andMapBinderBinding.permitsDuplicates().- Specified by:
containsElementin interfaceMapBinderBinding<K>
-