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>>
Modifier and Type | Field and Description |
---|---|
private java.util.Set<Dependency<?>> |
dependencies |
private SingleParameterInjector<V>[] |
injectors
An array of all the injectors.
|
private K[] |
keys |
bindingSelection
provisionCallback
Modifier | Constructor and Description |
---|---|
private |
RealMapProvider(RealMapBinder.BindingSelection<K,V> bindingSelection) |
Modifier and Type | Method and Description |
---|---|
<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.
|
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 to
MapBinderBinding.getEntries() , but can be used on a MapBinderBinding retrieved from Elements.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 the
Key for the map. |
TypeLiteral<V> |
getValueTypeLiteral()
Returns the TypeLiteral describing the values of the map.
|
boolean |
permitsDuplicates()
Returns true if the MapBinder permits duplicates.
|
equals, hashCode, initialize
get, get, getSource
private java.util.Set<Dependency<?>> dependencies
private SingleParameterInjector<V>[] injectors
This is parallel to array of keys below
private K[] keys
private RealMapProvider(RealMapBinder.BindingSelection<K,V> bindingSelection)
private RealMapBinder.BindingSelection<K,V> getBindingSelection()
protected void doInitialize(InjectorImpl injector, Errors errors) throws ErrorsException
RealMapBinder.RealMapBinderProviderWithDependencies
doInitialize
in class RealMapBinder.RealMapBinderProviderWithDependencies<K,V,java.util.Map<K,V>>
ErrorsException
protected java.util.Map<K,V> doProvision(InternalContext context, Dependency<?> dependency) throws InternalProvisionException
InternalProviderInstanceBindingImpl.Factory
doProvision
in class InternalProviderInstanceBindingImpl.Factory<java.util.Map<K,V>>
InternalProvisionException
- if a value cannot be providedpublic java.util.Set<Dependency<?>> getDependencies()
HasDependencies
Injector
will be
included in the returned set.getDependencies
in interface HasDependencies
public <B,W> W acceptExtensionVisitor(BindingTargetVisitor<B,W> visitor, ProviderInstanceBinding<? extends B> binding)
ProviderWithExtensionVisitor
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'.
acceptExtensionVisitor
in interface ProviderWithExtensionVisitor<java.util.Map<K,V>>
public Key<java.util.Map<K,V>> getMapKey()
MapBinderBinding
Key
for the map.getMapKey
in interface MapBinderBinding<java.util.Map<K,V>>
public java.util.Set<Key<?>> getAlternateMapKeys()
MapBinderBinding
Map<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>>>
, and Map<K, Set<V>
.getAlternateMapKeys
in interface MapBinderBinding<java.util.Map<K,V>>
public TypeLiteral<K> getKeyTypeLiteral()
MapBinderBinding
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 a
TypeLiteral<String>
.
getKeyTypeLiteral
in interface MapBinderBinding<java.util.Map<K,V>>
public TypeLiteral<V> getValueTypeLiteral()
MapBinderBinding
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 a
TypeLiteral<Snack>
.
getValueTypeLiteral
in interface MapBinderBinding<java.util.Map<K,V>>
public java.util.List<java.util.Map.Entry<?,Binding<?>>> getEntries()
MapBinderBinding
UnsupportedOperationException
if it is called on an element retrieved from Elements.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
type List<Map.Entry<String, Binding<Snack>>>
.
getEntries
in interface MapBinderBinding<java.util.Map<K,V>>
public java.util.List<java.util.Map.Entry<?,Binding<?>>> getEntries(java.lang.Iterable<? extends Element> elements)
MapBinderBinding
MapBinderBinding.getEntries()
, but can be used on a MapBinderBinding retrieved from Elements.getElements(com.google.inject.Module...)
.
One way to use this is to pass in the results of Elements.getElements(com.google.inject.Module...)
as the elements
parameter.
This differs from MapBinderBinding.getEntries()
in that it will return duplicates if they are
present in the elements
passed in. This does not run the normal Guice de-duplication
that MapBinderBinding.getEntries()
does.
getEntries
in interface MapBinderBinding<java.util.Map<K,V>>
public boolean permitsDuplicates()
MapBinderBinding
UnsupportedOperationException
if it is called on a
MapBinderBinding retrieved from Elements.getElements(com.google.inject.Module...)
.permitsDuplicates
in interface MapBinderBinding<java.util.Map<K,V>>
public boolean containsElement(Element element)
MapBinderBinding
Elements.getElements(com.google.inject.Module...)
. Usually this is
only necessary if you are working with elements retrieved from modules (without an Injector),
otherwise MapBinderBinding.getEntries()
and MapBinderBinding.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()
and MapBinderBinding.permitsDuplicates()
.
containsElement
in interface MapBinderBinding<java.util.Map<K,V>>