Top Description Inners Fields Constructors Methods
com.google.inject.internal

public final Class RealMapBinder<K, V>

extends Object
implements Module
Class Inheritance
All Implemented Interfaces
com.google.inject.Module
Static Imports
com.google.inject.internal.Element.Type.MAPBINDER, .Errors.checkConfiguration, .Errors.checkNotNull, .RealMultibinder.setOf, com.google.inject.util.Types.newParameterizedType, .Types.newParameterizedTypeWithOwner

The actual mapbinder plays several roles:

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.

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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
RealMapBinder.BindingSelection<K, V>

The BindingSelection contains some of the core state and logic for the MapBinder.

private static class
RealMapBinder.ExtensionRealMapProvider<K, V>

Implementation of a provider instance for the map that also exposes details about the MapBinder using the extension SPI, delegating to another provider instance for non-extension (e.g, the actual provider instance info) data.

pack-priv static class
RealMapBinder.MultimapBinder<K, V>

Binds Map<K, Set<V>> and {Map<K, Set<Provider<V>>>.

pack-priv static class
RealMapBinder.ProviderMapEntry<K, V>

A factory for a Map.Entry<K, Provider<V>>.

private abstract static class
RealMapBinder.RealMapBinderProviderWithDependencies<K, V, P>

A base class for ProviderWithDependencies that need equality based on a specific object.

private abstract static class
RealMapBinder.RealMultimapBinderProviderWithDependencies<K, V, P>

A base class for ProviderWithDependencies that need equality based on a specific object.

private static class

Field Summary

Modifier and TypeField and Description
private final Binder
private final RealMapBinder.BindingSelection<K, V>
private final RealMultibinder<Map.Entry<K, Provider<V>>>
private static final ImmutableSet<Dependency<?>>

Constructor Summary

AccessConstructor and Description
private
RealMapBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Key<Map<K, V>> mapKey, RealMultibinder<Map.Entry<K, Provider<V>>> entrySetBinder)

Method Summary

Modifier and TypeMethod and Description
public LinkedBindingBuilder<V>
addBinding(K key)

This creates two bindings.

public void
configure(Binder binder)

Implements com.google.inject.Module.configure.

Contributes bindings and other configurations for this module to binder.
private static <K, V> InternalProvisionException
createNullValueException(K key, Binding<V> binding)

pack-priv static <K, V> TypeLiteral<Map.Entry<K, Provider<V>>>
pack-priv static <K, V> TypeLiteral<Map.Entry<K, Provider<V>>>
entryOfProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)

public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
pack-priv Key<V>
getKeyForNewValue(K key)

Adds a binding to the map for the given key.

private static <T> Key<Provider<T>>
getKeyOfProvider(Key<T> valueKey)

Given a Key<T> will return a Key<Provider<T>>.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
pack-priv static <K, V> TypeLiteral<Map<K, V>>
mapOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)

pack-priv static <K, V> TypeLiteral<Map<K, Collection<Provider<V>>>>
pack-priv static <K, V> TypeLiteral<Map<K, Collection<Provider<V>>>>
pack-priv static <K, V> TypeLiteral<Map<K, Provider<V>>>
pack-priv static <K, V> TypeLiteral<Map<K, Provider<V>>>
mapOfProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)

pack-priv static <K, V> TypeLiteral<Map<K, Set<Provider<V>>>>
pack-priv static <K, V> TypeLiteral<Map<K, Set<Provider<V>>>>
mapOfSetOfProviderOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType)

public static <K, V> RealMapBinder<K, V>
newMapRealBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType)

Returns a new mapbinder that collects entries of keyType/valueType in a Map that is itself bound with no binding annotation.

public static <K, V> RealMapBinder<K, V>
newRealMapBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Annotation annotation)

Returns a new mapbinder that collects entries of keyType/valueType in a Map that is itself bound with annotation.

public static <K, V> RealMapBinder<K, V>
newRealMapBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Class<? extends Annotation> annotationType)

Returns a new mapbinder that collects entries of keyType/valueType in a Map that is itself bound with annotationType.

pack-priv static <K, V> RealMapBinder<K, V>
newRealMapBinder(Binder binder, TypeLiteral<K> keyType, Key<V> valueTypeAndAnnotation)

private static <K, V> RealMapBinder<K, V>
newRealMapBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, Key<Map<K, V>> mapKey, RealMultibinder<Map.Entry<K, Provider<V>>> entrySetBinder)

public void
pack-priv static <K, V> TypeLiteral<Set<Map.Entry<K, Provider<V>>>>
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait