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>>
Modifier and Type | Field and Description |
---|---|
private java.util.List<Binding<T>> |
bindings |
private RealMultibinder.BindingSelection<T> |
bindingSelection |
private SingleParameterInjector<T>[] |
injectors |
private boolean |
permitDuplicates |
provisionCallback
Constructor and Description |
---|
RealMultibinderProvider(RealMultibinder.BindingSelection<T> bindingSelection) |
Modifier and Type | Method and Description |
---|---|
<B,V> V |
acceptExtensionVisitor(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<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.
|
get, get, getSource
private final RealMultibinder.BindingSelection<T> bindingSelection
private SingleParameterInjector<T>[] injectors
private boolean permitDuplicates
RealMultibinderProvider(RealMultibinder.BindingSelection<T> bindingSelection)
public java.util.Set<Dependency<?>> getDependencies()
HasDependencies
Injector
will be
included in the returned set.getDependencies
in interface HasDependencies
void initialize(InjectorImpl injector, Errors errors) throws ErrorsException
InternalProviderInstanceBindingImpl.Factory
Will be called exactly once, prior to any call to InternalProviderInstanceBindingImpl.Factory.doProvision(com.google.inject.internal.InternalContext, com.google.inject.spi.Dependency<?>)
.
initialize
in class InternalProviderInstanceBindingImpl.Factory<java.util.Set<T>>
ErrorsException
protected java.util.Set<T> doProvision(InternalContext context, Dependency<?> dependency) throws InternalProvisionException
InternalProviderInstanceBindingImpl.Factory
doProvision
in class InternalProviderInstanceBindingImpl.Factory<java.util.Set<T>>
InternalProvisionException
- if a value cannot be providedprivate InternalProvisionException newNullEntryException(int i)
public <B,V> V acceptExtensionVisitor(BindingTargetVisitor<B,V> 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.Set<T>>
private InternalProvisionException newDuplicateValuesException(com.google.common.collect.ImmutableSet<T> set, T[] values)
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public Key<java.util.Set<T>> getSetKey()
MultibinderBinding
getSetKey
in interface MultibinderBinding<java.util.Set<T>>
public TypeLiteral<?> getElementTypeLiteral()
MultibinderBinding
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
TypeLiteral<String>
.
getElementTypeLiteral
in interface MultibinderBinding<java.util.Set<T>>
public java.util.List<Binding<?>> getElements()
MultibinderBinding
UnsupportedOperationException
if it is called on an element
retrieved from Elements.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 type
List<Binding<String>>
.
getElements
in interface MultibinderBinding<java.util.Set<T>>
public boolean permitsDuplicates()
MultibinderBinding
UnsupportedOperationException
if it is called on a
MultibinderBinding retrieved from Elements.getElements(com.google.inject.Module...)
.permitsDuplicates
in interface MultibinderBinding<java.util.Set<T>>
public boolean containsElement(Element element)
MultibinderBinding
Elements.getElements(com.google.inject.Module...)
.
Usually this is only necessary if you are working with elements retrieved from modules (without
an Injector), otherwise MultibinderBinding.getElements()
and MultibinderBinding.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()
and MultibinderBinding.permitsDuplicates()
.
containsElement
in interface MultibinderBinding<java.util.Set<T>>