Class RealMapBinder.BindingSelection<K,V>

java.lang.Object
com.google.inject.internal.RealMapBinder.BindingSelection<K,V>
Enclosing class:
RealMapBinder<K,V>

private static final class RealMapBinder.BindingSelection<K,V> extends Object
The BindingSelection contains some of the core state and logic for the MapBinder.

It lazily computes the value for keys for various permutations of Maps that are provided by this module. It also builds up maps from K to Binding<V>, which is used by all of the internal factories to actually provide the desired maps.

During initialization time there is only one BindingSelection. It is possible that multiple different BindingSelections are constructed. Specifically, in the case of two different modules each adding bindings to the same MapBinder. If that happens, we define the BindingSelection held by the RealMapBinder.RealMapProvider to be the authoritative one. The logic for this exists in RealMapBinder.RealMultimapBinderProviderWithDependencies. This is done to avoid confusion because the BindingSelection contains mutable state.

  • Field Details

    • keyType

      private final TypeLiteral<K> keyType
    • valueType

      private final TypeLiteral<V> valueType
    • mapKey

      private final Key<Map<K,V>> mapKey
    • javaxProviderMapKey

      private Key<Map<K,javax.inject.Provider<V>>> javaxProviderMapKey
    • providerMapKey

      private Key<Map<K,Provider<V>>> providerMapKey
    • multimapKey

      private Key<Map<K,Set<V>>> multimapKey
    • providerSetMultimapKey

      private Key<Map<K,Set<Provider<V>>>> providerSetMultimapKey
    • javaxProviderSetMultimapKey

      private Key<Map<K,Set<javax.inject.Provider<V>>>> javaxProviderSetMultimapKey
    • providerCollectionMultimapKey

      private Key<Map<K,Collection<Provider<V>>>> providerCollectionMultimapKey
    • javaxProviderCollectionMultimapKey

      private Key<Map<K,Collection<javax.inject.Provider<V>>>> javaxProviderCollectionMultimapKey
    • entrySetJavaxProviderKey

      private Key<Set<Map.Entry<K,javax.inject.Provider<V>>>> entrySetJavaxProviderKey
    • mapOfKeyExtendsValueKey

      private Key<Map<K,? extends V>> mapOfKeyExtendsValueKey
    • entrySetBinder

      private final RealMultibinder<Map.Entry<K,Provider<V>>> entrySetBinder
    • initializationState

    • mapBindings

      private com.google.common.collect.ImmutableMap<K,Binding<V>> mapBindings
      These are built during initialization and used by all factories to actually provide the relevant maps. These contain all of the necessary information about the map binder.
    • multimapBindings

      private com.google.common.collect.ImmutableMap<K,Set<Binding<V>>> multimapBindings
    • entries

      private com.google.common.collect.ImmutableList<Map.Entry<K,Binding<V>>> entries
    • permitsDuplicates

      private boolean permitsDuplicates
      Indicates if this Map permits duplicates. It is initialized during initialization by querying the injector. This is done because multiple different modules can contribute to a MapBinder, and any one could set permitDuplicates.
  • Constructor Details

  • Method Details

    • tryInitialize

      private boolean tryInitialize(InjectorImpl injector, Errors errors)
      Will initialize internal data structures.
      Returns:
      true if initialization was successful, false if there were errors
    • reportDuplicateKeysError

      private static <K, V> void reportDuplicateKeysError(Key<Map<K,V>> mapKey, com.google.common.collect.Multimap<K,Binding<V>> duplicates, Errors errors)
    • containsElement

      private boolean containsElement(Element element)
    • matchesValueKey

      private boolean matchesValueKey(Key<?> key)
      Returns true if the key indicates this is a value in the map.
    • getProviderMapKey

      private Key<Map<K,Provider<V>>> getProviderMapKey()
    • getJavaxProviderMapKey

      private Key<Map<K,javax.inject.Provider<V>>> getJavaxProviderMapKey()
    • getMultimapKey

      private Key<Map<K,Set<V>>> getMultimapKey()
    • getProviderSetMultimapKey

      private Key<Map<K,Set<Provider<V>>>> getProviderSetMultimapKey()
    • getJavaxProviderSetMultimapKey

      private Key<Map<K,Set<javax.inject.Provider<V>>>> getJavaxProviderSetMultimapKey()
    • getProviderCollectionMultimapKey

      private Key<Map<K,Collection<Provider<V>>>> getProviderCollectionMultimapKey()
    • getJavaxProviderCollectionMultimapKey

      private Key<Map<K,Collection<javax.inject.Provider<V>>>> getJavaxProviderCollectionMultimapKey()
    • getEntrySetJavaxProviderKey

      private Key<Set<Map.Entry<K,javax.inject.Provider<V>>>> getEntrySetJavaxProviderKey()
    • getMapOfKeyExtendsValueKey

      private Key<Map<K,? extends V>> getMapOfKeyExtendsValueKey()
    • getMapBindings

      private com.google.common.collect.ImmutableMap<K,Binding<V>> getMapBindings()
    • getMultimapBindings

      private com.google.common.collect.ImmutableMap<K,Set<Binding<V>>> getMultimapBindings()
    • getEntries

      private com.google.common.collect.ImmutableList<Map.Entry<K,Binding<V>>> getEntries()
    • isInitialized

      private boolean isInitialized()
    • getKeyType

      private TypeLiteral<K> getKeyType()
    • getValueType

      private TypeLiteral<V> getValueType()
    • getMapKey

      private Key<Map<K,V>> getMapKey()
    • getEntrySetBinder

      private RealMultibinder<Map.Entry<K,Provider<V>>> getEntrySetBinder()
    • permitsDuplicates

      private boolean permitsDuplicates()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object