Class RealMapBinder.ExtensionRealMapProvider<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
FieldsFields inherited from class com.google.inject.internal.RealMapBinder.RealMapBinderProviderWithDependencies
bindingSelection
Fields inherited from class com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory
provisionCallback
-
Constructor Summary
Constructors -
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.boolean
containsElement
(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 void
doInitialize
(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.(package 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 theKey
for the map.Returns the TypeLiteral describing the values of the map.boolean
Returns true if the MapBinder permits duplicates.Methods inherited from class com.google.inject.internal.RealMapBinder.RealMapBinderProviderWithDependencies
equals, hashCode, initialize
Methods inherited from class com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory
get, get, getSource
-
Field Details
-
delegate
-
-
Constructor Details
-
ExtensionRealMapProvider
ExtensionRealMapProvider(RealMapBinder.RealMapProvider<K, V> delegate)
-
-
Method Details
-
getBindingSelection
RealMapBinder.BindingSelection<K,V> getBindingSelection() -
doInitialize
Description copied from class:RealMapBinder.RealMapBinderProviderWithDependencies
Initialize the factory. BindingSelection is guaranteed to be initialized at this point and this will be called prior to any provisioning.- Specified by:
doInitialize
in 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.Factory
Creates an object to be injected.- Specified by:
doProvision
in classInternalProviderInstanceBindingImpl.Factory<Map<K,
V>> - Returns:
- instance to be injected
- Throws:
InternalProvisionException
- if a value cannot be provided
-
getDependencies
Description copied from interface:HasDependencies
Returns the known dependencies for this type. If this has dependencies whose values are not known statically, a dependency for theInjector
will be included in the returned set.- Specified by:
getDependencies
in interfaceHasDependencies
- Returns:
- a possibly empty set
-
acceptExtensionVisitor
public <B,W> W acceptExtensionVisitor(BindingTargetVisitor<B, W> visitor, ProviderInstanceBinding<? extends B> binding) Description copied from interface:ProviderWithExtensionVisitor
Instructs 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:
acceptExtensionVisitor
in interfaceProviderWithExtensionVisitor<K>
-
getMapKey
Description copied from interface:MapBinderBinding
Returns theKey
for the map.- Specified by:
getMapKey
in interfaceMapBinderBinding<K>
-
getAlternateMapKeys
Description copied from interface:MapBinderBinding
Returns 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>>>
,Map<K, Set<V>
, andMap<K, ? extends V>
.- Specified by:
getAlternateMapKeys
in interfaceMapBinderBinding<K>
-
getKeyTypeLiteral
Description copied from interface:MapBinderBinding
Returns 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:
getKeyTypeLiteral
in interfaceMapBinderBinding<K>
-
getValueTypeLiteral
Description copied from interface:MapBinderBinding
Returns 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:
getValueTypeLiteral
in interfaceMapBinderBinding<K>
-
getEntries
Description copied from interface:MapBinderBinding
Returns 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 throwUnsupportedOperationException
if 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:
getEntries
in interfaceMapBinderBinding<K>
-
getEntries
Description copied from interface:MapBinderBinding
Similar 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 theelements
parameter.This differs from
MapBinderBinding.getEntries()
in that it will return duplicates if they are present in theelements
passed in. This does not run the normal Guice de-duplication thatMapBinderBinding.getEntries()
does.- Specified by:
getEntries
in interfaceMapBinderBinding<K>
-
permitsDuplicates
public boolean permitsDuplicates()Description copied from interface:MapBinderBinding
Returns true if the MapBinder permits duplicates. This is only supported on bindings returned from an injector. This will throwUnsupportedOperationException
if it is called on a MapBinderBinding retrieved fromElements.getElements(com.google.inject.Module...)
.- Specified by:
permitsDuplicates
in interfaceMapBinderBinding<K>
-
containsElement
Description copied from interface:MapBinderBinding
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. 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:
containsElement
in interfaceMapBinderBinding<K>
-