Class RealMultibinder.RealMultibinderProvider<T>
- java.lang.Object
-
- com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory<java.util.Set<T>>
-
- com.google.inject.internal.RealMultibinder.RealMultibinderProvider<T>
-
- All Implemented Interfaces:
InternalFactory<java.util.Set<T>>
,MultibinderBinding<java.util.Set<T>>
,Provider<java.util.Set<T>>
,HasDependencies
,ProviderWithExtensionVisitor<java.util.Set<T>>
,javax.inject.Provider<java.util.Set<T>>
- Enclosing class:
- RealMultibinder<T>
private static final class RealMultibinder.RealMultibinderProvider<T> extends InternalProviderInstanceBindingImpl.Factory<java.util.Set<T>> implements ProviderWithExtensionVisitor<java.util.Set<T>>, MultibinderBinding<java.util.Set<T>>
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<Binding<T>>
bindings
private RealMultibinder.BindingSelection<T>
bindingSelection
private SingleParameterInjector<T>[]
injectors
private boolean
permitDuplicates
-
Fields inherited from class com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory
provisionCallback
-
-
Constructor Summary
Constructors Constructor Description RealMultibinderProvider(RealMultibinder.BindingSelection<T> bindingSelection)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <B,V>
VacceptExtensionVisitor(BindingTargetVisitor<B,V> 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 Multibinder uses the given Element.protected java.util.Set<T>
doProvision(InternalContext context, Dependency<?> dependency)
Creates an object to be injected.boolean
equals(java.lang.Object obj)
java.util.Set<Key<?>>
getAlternateSetKeys()
Returns the keys of other bindings that represent this set.java.util.Set<Dependency<?>>
getDependencies()
Returns the known dependencies for this type.java.util.List<Binding<?>>
getElements()
Returns all bindings that make up the set.TypeLiteral<?>
getElementTypeLiteral()
Returns the TypeLiteral that describes the type of elements in the set.Key<java.util.Set<T>>
getSetKey()
Returns the key for the set.int
hashCode()
(package private) void
initialize(InjectorImpl injector, Errors errors)
A callback that allows for implementations to fetch dependencies on other bindings.private InternalProvisionException
newDuplicateValuesException(com.google.common.collect.ImmutableSet<T> set, T[] values)
private InternalProvisionException
newNullEntryException(int i)
boolean
permitsDuplicates()
Returns true if the multibinder permits duplicates.-
Methods inherited from class com.google.inject.internal.InternalProviderInstanceBindingImpl.Factory
get, get, getSource
-
-
-
-
Field Detail
-
bindingSelection
private final RealMultibinder.BindingSelection<T> bindingSelection
-
injectors
private SingleParameterInjector<T>[] injectors
-
permitDuplicates
private boolean permitDuplicates
-
-
Constructor Detail
-
RealMultibinderProvider
RealMultibinderProvider(RealMultibinder.BindingSelection<T> bindingSelection)
-
-
Method Detail
-
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
-
initialize
void initialize(InjectorImpl injector, Errors errors) throws ErrorsException
Description copied from class:InternalProviderInstanceBindingImpl.Factory
A callback that allows for implementations to fetch dependencies on other bindings.Will be called exactly once, prior to any call to
InternalProviderInstanceBindingImpl.Factory.doProvision(com.google.inject.internal.InternalContext, com.google.inject.spi.Dependency<?>)
.- Specified by:
initialize
in classInternalProviderInstanceBindingImpl.Factory<java.util.Set<T>>
- Throws:
ErrorsException
-
doProvision
protected java.util.Set<T> 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.Set<T>>
- Returns:
- instance to be injected
- Throws:
InternalProvisionException
- if a value cannot be provided
-
newNullEntryException
private InternalProvisionException newNullEntryException(int i)
-
acceptExtensionVisitor
public <B,V> V acceptExtensionVisitor(BindingTargetVisitor<B,V> 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<T>
-
newDuplicateValuesException
private InternalProvisionException newDuplicateValuesException(com.google.common.collect.ImmutableSet<T> set, T[] values)
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
getSetKey
public Key<java.util.Set<T>> getSetKey()
Description copied from interface:MultibinderBinding
Returns the key for the set.- Specified by:
getSetKey
in interfaceMultibinderBinding<T>
-
getAlternateSetKeys
public java.util.Set<Key<?>> getAlternateSetKeys()
Description copied from interface:MultibinderBinding
Returns the keys of other bindings that represent this set. This will return an entry forCollection<com.google.inject.Provider<V>>
andCollection<javax.inject.Provider<V>>
.- Specified by:
getAlternateSetKeys
in interfaceMultibinderBinding<T>
-
getElementTypeLiteral
public TypeLiteral<?> getElementTypeLiteral()
Description copied from interface:MultibinderBinding
Returns the TypeLiteral that describes the type of elements in the set.The elements will always match the type Set's generic type. For example, if getSetKey returns a key of
Set<String>
, then this will always return aTypeLiteral<String>
.- Specified by:
getElementTypeLiteral
in interfaceMultibinderBinding<T>
-
getElements
public java.util.List<Binding<?>> getElements()
Description copied from interface:MultibinderBinding
Returns all bindings that make up the set. 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 Set's generic type. For example, if getSetKey returns a key of
Set<String>
, then this will always return a list of typeList<Binding<String>>
.- Specified by:
getElements
in interfaceMultibinderBinding<T>
-
permitsDuplicates
public boolean permitsDuplicates()
Description copied from interface:MultibinderBinding
Returns true if the multibinder permits duplicates. This is only supported on bindings returned from an injector. This will throwUnsupportedOperationException
if it is called on a MultibinderBinding retrieved fromElements.getElements(com.google.inject.Module...)
.- Specified by:
permitsDuplicates
in interfaceMultibinderBinding<T>
-
containsElement
public boolean containsElement(Element element)
Description copied from interface:MultibinderBinding
Returns true if this Multibinder uses the given Element. This will be true for bindings that derive the elements of the set and other bindings that Multibinder uses internally. This will work for MultibinderBindings 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), otherwiseMultibinderBinding.getElements()
andMultibinderBinding.permitsDuplicates()
are better options.If you need to introspect the details of the set, such as the values or if it permits duplicates, it is necessary to pass the elements through an Injector and use
MultibinderBinding.getElements()
andMultibinderBinding.permitsDuplicates()
.- Specified by:
containsElement
in interfaceMultibinderBinding<T>
-
-