public final class RealMultibinder<T> extends java.lang.Object implements Module
As a Multibinder, it acts as a factory for LinkedBindingBuilders for each of the set's elements. Each binding is given an annotation that identifies it as a part of this set.
As a Module, it installs the binding to the set itself. As a module, this implements equals() and hashcode() in order to trick Guice into executing its configure() method only once. That makes it so that multiple multibinders can be created for the same target collection, but only one is bound. Since the list of bindings is retrieved from the injector itself (and not the multibinder), each multibinder has access to all contributions from all multibinders.
As a Provider, this constructs the set instances.
We use a subclass to hide 'implements Module, Provider' from the public API.
Modifier and Type | Class and Description |
---|---|
private static class |
RealMultibinder.BindingSelection<T> |
private static class |
RealMultibinder.PermitDuplicatesModule
We install the permit duplicates configuration as its own binding, all by itself.
|
private static class |
RealMultibinder.RealMultibinderCollectionOfProvidersProvider<T> |
private static class |
RealMultibinder.RealMultibinderProvider<T> |
Modifier and Type | Field and Description |
---|---|
private Binder |
binder |
private RealMultibinder.BindingSelection<T> |
bindingSelection |
Constructor and Description |
---|
RealMultibinder(Binder binder,
Key<T> key) |
Modifier and Type | Method and Description |
---|---|
LinkedBindingBuilder<T> |
addBinding() |
(package private) static <T> TypeLiteral<java.util.Collection<javax.inject.Provider<T>>> |
collectionOfJavaxProvidersOf(TypeLiteral<T> elementType) |
(package private) static <T> TypeLiteral<java.util.Collection<Provider<T>>> |
collectionOfProvidersOf(TypeLiteral<T> elementType) |
void |
configure(Binder binder)
Contributes bindings and other configurations for this module to
binder . |
(package private) boolean |
containsElement(Element element) |
boolean |
equals(java.lang.Object o) |
(package private) TypeLiteral<T> |
getElementTypeLiteral() |
(package private) Key<T> |
getKeyForNewItem()
Adds a new entry to the set and returns the key for it.
|
(package private) Key<java.util.Set<T>> |
getSetKey() |
(package private) java.lang.String |
getSetName() |
int |
hashCode() |
static <T> RealMultibinder<T> |
newRealSetBinder(Binder binder,
Key<T> key)
Implementation of newSetBinder.
|
void |
permitDuplicates() |
(package private) boolean |
permitsDuplicates(Injector injector) |
(package private) static <T> TypeLiteral<java.util.Set<T>> |
setOf(TypeLiteral<T> elementType) |
private final RealMultibinder.BindingSelection<T> bindingSelection
private final Binder binder
public static <T> RealMultibinder<T> newRealSetBinder(Binder binder, Key<T> key)
static <T> TypeLiteral<java.util.Set<T>> setOf(TypeLiteral<T> elementType)
static <T> TypeLiteral<java.util.Collection<Provider<T>>> collectionOfProvidersOf(TypeLiteral<T> elementType)
static <T> TypeLiteral<java.util.Collection<javax.inject.Provider<T>>> collectionOfJavaxProvidersOf(TypeLiteral<T> elementType)
public void configure(Binder binder)
Module
binder
.
Do not invoke this method directly to install submodules. Instead use
Binder.install(Module)
, which ensures that provider methods
are
discovered.
public void permitDuplicates()
public LinkedBindingBuilder<T> addBinding()
TypeLiteral<T> getElementTypeLiteral()
java.lang.String getSetName()
boolean permitsDuplicates(Injector injector)
boolean containsElement(Element element)
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object