Class RealMapBinder.RealMapProvider<K,V>
- java.lang.Object
-
- com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory<P>
-
- com.google.inject.internal.RealMapBinder.RealMapBinderProviderWithDependencies<K,V,java.util.Map<K,V>>
-
- com.google.inject.internal.RealMapBinder.RealMapProvider<K,V>
-
- All Implemented Interfaces:
InternalFactory<java.util.Map<K,V>>
,MapBinderBinding<java.util.Map<K,V>>
,Provider<java.util.Map<K,V>>
,HasDependencies
,ProviderWithExtensionVisitor<java.util.Map<K,V>>
,javax.inject.Provider<java.util.Map<K,V>>
- Enclosing class:
- RealMapBinder<K,V>
private static final class RealMapBinder.RealMapProvider<K,V> extends RealMapBinder.RealMapBinderProviderWithDependencies<K,V,java.util.Map<K,V>> implements ProviderWithExtensionVisitor<java.util.Map<K,V>>, MapBinderBinding<java.util.Map<K,V>>
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<Dependency<?>>
dependencies
private SingleParameterInjector<V>[]
injectors
An array of all the injectors.private K[]
keys
-
Fields inherited from class com.google.inject.internal.RealMapBinder.RealMapBinderProviderWithDependencies
bindingSelection
-
Fields inherited from class com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory
provisionCallback
-
-
Constructor Summary
Constructors Modifier Constructor Description private
RealMapProvider(RealMapBinder.BindingSelection<K,V> bindingSelection)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <B,W>
WacceptExtensionVisitor(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.protected java.util.Map<K,V>
doProvision(InternalContext context, Dependency<?> dependency)
Creates an object to be injected.java.util.Set<Key<?>>
getAlternateMapKeys()
Returns the keys of other bindings that represent this map.private RealMapBinder.BindingSelection<K,V>
getBindingSelection()
java.util.Set<Dependency<?>>
getDependencies()
Returns the known dependencies for this type.java.util.List<java.util.Map.Entry<?,Binding<?>>>
getEntries()
Returns all entries in the Map.java.util.List<java.util.Map.Entry<?,Binding<?>>>
getEntries(java.lang.Iterable<? extends Element> elements)
Similar toMapBinderBinding.getEntries()
, but can be used on a MapBinderBinding retrieved fromElements.getElements(com.google.inject.Module...)
.TypeLiteral<K>
getKeyTypeLiteral()
Returns the TypeLiteral describing the keys of the map.Key<java.util.Map<K,V>>
getMapKey()
Returns theKey
for the map.TypeLiteral<V>
getValueTypeLiteral()
Returns the TypeLiteral describing the values of the map.boolean
permitsDuplicates()
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 Detail
-
dependencies
private java.util.Set<Dependency<?>> dependencies
-
injectors
private SingleParameterInjector<V>[] injectors
An array of all the injectors.This is parallel to array of keys below
-
keys
private K[] keys
-
-
Constructor Detail
-
RealMapProvider
private RealMapProvider(RealMapBinder.BindingSelection<K,V> bindingSelection)
-
-
Method Detail
-
getBindingSelection
private RealMapBinder.BindingSelection<K,V> getBindingSelection()
-
doInitialize
protected void doInitialize(InjectorImpl injector, Errors errors) throws ErrorsException
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,java.util.Map<K,V>>
- Throws:
ErrorsException
-
doProvision
protected java.util.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<java.util.Map<K,V>>
- Returns:
- instance to be injected
- Throws:
InternalProvisionException
- if a value cannot be provided
-
getDependencies
public java.util.Set<Dependency<?>> 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
public Key<java.util.Map<K,V>> getMapKey()
Description copied from interface:MapBinderBinding
Returns theKey
for the map.- Specified by:
getMapKey
in interfaceMapBinderBinding<K>
-
getAlternateMapKeys
public java.util.Set<Key<?>> 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>>>
, andMap<K, Set<V>
.- Specified by:
getAlternateMapKeys
in interfaceMapBinderBinding<K>
-
getKeyTypeLiteral
public TypeLiteral<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
public TypeLiteral<V> 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
public java.util.List<java.util.Map.Entry<?,Binding<?>>> 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
public java.util.List<java.util.Map.Entry<?,Binding<?>>> getEntries(java.lang.Iterable<? extends Element> elements)
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
public boolean containsElement(Element element)
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>
-
-