static final class MapBinder.RealMapBinder<K,V> extends MapBinder<K,V> implements Module
As a MapBinder, it acts as a factory for LinkedBindingBuilders for
each of the map's values. It delegates to a Multibinder
of
entries (keys to value providers).
As a Module, it installs the binding to the map itself, as well as to a corresponding map whose values are providers. It uses the entry set multibinder to construct the map and the provider map.
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 mapbinders can be created for the same target map, but only one is bound. Since the list of bindings is retrieved from the injector itself (and not the mapbinder), each mapbinder has access to all contributions from all equivalent mapbinders.
Rather than binding a single Map.Entry<K, V>, the map binder binds keys and values independently. This allows the values to be properly scoped.
We use a subclass to hide 'implements Module' from the public API.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
MapBinder.RealMapBinder.MultimapBinder<K,V>
Binds
Map<K, Set<V>> and {Map<K, Set<Provider<V>>> . |
(package private) static class |
MapBinder.RealMapBinder.ProviderMapEntry<K,V>
A Provider that Map.Entry that is also a Provider.
|
private static class |
MapBinder.RealMapBinder.RealMapBinderProviderWithDependencies<T>
A base class for ProviderWithDependencies that need equality
based on a specific object.
|
(package private) class |
MapBinder.RealMapBinder.RealMapProvider |
private static class |
MapBinder.RealMapBinder.RealMapWithExtensionProvider<T> |
(package private) class |
MapBinder.RealMapBinder.RealProviderMapProvider |
(package private) static class |
MapBinder.RealMapBinder.ValueProvider<V> |
MapBinder.RealMapBinder<K,V>
Modifier and Type | Field and Description |
---|---|
private Binder |
binder |
private java.util.Map<K,java.lang.String> |
duplicateKeyErrorMessages |
private Multibinder.RealMultibinder<java.util.Map.Entry<K,Provider<V>>> |
entrySetBinder |
private Key<java.util.Set<java.util.Map.Entry<K,javax.inject.Provider<V>>>> |
entrySetJavaxProviderKey |
private Key<java.util.Map<K,java.util.Collection<javax.inject.Provider<V>>>> |
javaxProviderCollectionMultimapKey |
private Key<java.util.Map<K,javax.inject.Provider<V>>> |
javaxProviderMapKey |
private Key<java.util.Map<K,java.util.Set<javax.inject.Provider<V>>>> |
javaxProviderSetMultimapKey |
private TypeLiteral<K> |
keyType |
private com.google.common.collect.ImmutableList<java.util.Map.Entry<K,Binding<V>>> |
mapBindings |
private Key<java.util.Map<K,V>> |
mapKey |
private Key<java.util.Map<K,java.util.Set<V>>> |
multimapKey |
private boolean |
permitDuplicates |
private Key<java.util.Map<K,java.util.Collection<Provider<V>>>> |
providerCollectionMultimapKey |
private Key<java.util.Map<K,Provider<V>>> |
providerMapKey |
private Key<java.util.Map<K,java.util.Set<Provider<V>>>> |
providerSetMultimapKey |
private TypeLiteral<V> |
valueType |
Modifier | Constructor and Description |
---|---|
private |
RealMapBinder(Binder binder,
TypeLiteral<K> keyType,
TypeLiteral<V> valueType,
Key<java.util.Map<K,V>> mapKey,
Multibinder<java.util.Map.Entry<K,Provider<V>>> entrySetBinder) |
Modifier and Type | Method and Description |
---|---|
LinkedBindingBuilder<V> |
addBinding(K key)
This creates two bindings.
|
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) Key<V> |
getKeyForNewValue(K key) |
int |
hashCode() |
private boolean |
isInitialized() |
private boolean |
matchesValueKey(Key<?> key)
Returns true if the key indicates this is a value in the map.
|
private com.google.common.collect.Multimap<K,java.lang.String> |
newLinkedKeyArrayValueMultimap() |
MapBinder<K,V> |
permitDuplicates()
Configures the
MapBinder to handle duplicate entries. |
(package private) void |
updateDuplicateKeyMessage(K k,
java.lang.String errMsg)
Sets the error message to be shown if the key had duplicate non-equal bindings.
|
entryOfJavaxProviderOf, entryOfProviderOf, mapOf, mapOfCollectionOfJavaxProviderOf, mapOfCollectionOfProviderOf, mapOfJavaxProviderOf, mapOfProviderOf, mapOfSetOfJavaxProviderOf, mapOfSetOfProviderOf, newMapBinder, newMapBinder, newMapBinder, newMapBinder, newMapBinder, newMapBinder, newRealMapBinder, setOfEntryOfJavaxProviderOf
private final TypeLiteral<K> keyType
private final TypeLiteral<V> valueType
private final Key<java.util.Map<K,javax.inject.Provider<V>>> javaxProviderMapKey
private final Key<java.util.Map<K,java.util.Set<Provider<V>>>> providerSetMultimapKey
private final Key<java.util.Map<K,java.util.Set<javax.inject.Provider<V>>>> javaxProviderSetMultimapKey
private final Key<java.util.Map<K,java.util.Collection<Provider<V>>>> providerCollectionMultimapKey
private final Key<java.util.Map<K,java.util.Collection<javax.inject.Provider<V>>>> javaxProviderCollectionMultimapKey
private final Key<java.util.Set<java.util.Map.Entry<K,javax.inject.Provider<V>>>> entrySetJavaxProviderKey
private final Multibinder.RealMultibinder<java.util.Map.Entry<K,Provider<V>>> entrySetBinder
private final java.util.Map<K,java.lang.String> duplicateKeyErrorMessages
private Binder binder
private boolean permitDuplicates
private RealMapBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Key<java.util.Map<K,V>> mapKey, Multibinder<java.util.Map.Entry<K,Provider<V>>> entrySetBinder)
void updateDuplicateKeyMessage(K k, java.lang.String errMsg)
public MapBinder<K,V> permitDuplicates()
MapBinder
MapBinder
to handle duplicate entries.
When multiple equal keys are bound, the value that gets included in the map is arbitrary.
In addition to the Map<K, V>
and Map<K, Provider<V>>
maps that are normally bound, a Map<K, Set<V>>
and
Map<K, Set<Provider<V>>>
are also bound, which contain
all values bound to each key.
When multiple modules contribute elements to the map, this configuration option impacts all of them.
permitDuplicates
in class MapBinder<K,V>
public LinkedBindingBuilder<V> addBinding(K key)
Map.Entry<K, Provider<V>>
and another for V
.addBinding
in class MapBinder<K,V>
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.
boolean containsElement(Element element)
private boolean matchesValueKey(Key<?> key)
private boolean isInitialized()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
private com.google.common.collect.Multimap<K,java.lang.String> newLinkedKeyArrayValueMultimap()