Interface MapBinderBinding<T>
-
- Type Parameters:
T
- The fully qualified type of the map, including Map. For example:MapBinderBinding<Map<String, Snack>>
public interface MapBinderBinding<T>
A binding for a MapBinder.Although MapBinders may be injected through a variety of generic types (
Map<K, V>
,Map<K, ? extends V>
,Map<K, Provider<V>>
,Map<K, Set<V>>
,Map<K, Set<Provider<V>>
, and evenSet<Map.Entry<K, Provider<V>>
), a MapBinderBinding exists only on the Binding associated with the Map<K, V> key. Injectable map types can be discovered usinggetMapKey()
(which will return theMap<K, V>
key), orgetAlternateMapKeys()
(which will return the other keys that can inject this data). Other bindings can be validated to be derived from this MapBinderBinding usingcontainsElement(Element)
.- Since:
- 3.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
containsElement(Element element)
Returns true if this MapBinder contains the given Element in order to build the map or uses the given Element in order to support building and injecting the map.Set<Key<?>>
getAlternateMapKeys()
Returns the keys of other bindings that represent this map.List<Map.Entry<?,Binding<?>>>
getEntries()
Returns all entries in the Map.List<Map.Entry<?,Binding<?>>>
getEntries(Iterable<? extends Element> elements)
Similar togetEntries()
, but can be used on a MapBinderBinding retrieved fromElements.getElements(com.google.inject.Module...)
.TypeLiteral<?>
getKeyTypeLiteral()
Returns the TypeLiteral describing the keys of the map.Key<T>
getMapKey()
Returns theKey
for the map.TypeLiteral<?>
getValueTypeLiteral()
Returns the TypeLiteral describing the values of the map.boolean
permitsDuplicates()
Returns true if the MapBinder permits duplicates.
-
-
-
Method Detail
-
getAlternateMapKeys
Set<Key<?>> getAlternateMapKeys()
Returns the keys of other bindings that represent this map. This will return an entry forMap<K, com.google.inject.Provider<V>>
,Map<K, javax.inject.Provider<V>>
,Map<K, Set<com.google.inject.Provider<V>>>
,Map<K, Set<javax.inject.Provider<V>>>
,Map<K, Collection<com.google.inject.Provider<V>>>
,Map<K, Collection<javax.inject.Provider<V>>>
,Map<K, Set<V>
, andMap<K, ? extends V>
.- Since:
- 4.2.3
-
getKeyTypeLiteral
TypeLiteral<?> getKeyTypeLiteral()
Returns the TypeLiteral describing the keys of the map.The TypeLiteral will always match the type Map's generic type. For example, if getMapKey returns a key of
Map<String, Snack>
, then this will always return aTypeLiteral<String>
.
-
getValueTypeLiteral
TypeLiteral<?> getValueTypeLiteral()
Returns the TypeLiteral describing the values of the map.The TypeLiteral will always match the type Map's generic type. For example, if getMapKey returns a key of
Map<String, Snack>
, then this will always return aTypeLiteral<Snack>
.
-
getEntries
List<Map.Entry<?,Binding<?>>> getEntries()
Returns all entries in the Map. The returned list of Map.Entries contains the key and a binding to the value. Duplicate keys or values will exist as separate Map.Entries in the returned list. This is only supported on bindings returned from an injector. This will throwUnsupportedOperationException
if it is called on an element retrieved fromElements.getElements(com.google.inject.Module...)
.The elements will always match the type Map's generic type. For example, if getMapKey returns a key of
Map<String, Snack>
, then this will always return a list of typeList<Map.Entry<String, Binding<Snack>>>
.
-
getEntries
List<Map.Entry<?,Binding<?>>> getEntries(Iterable<? extends Element> elements)
Similar togetEntries()
, but can be used on a MapBinderBinding retrieved fromElements.getElements(com.google.inject.Module...)
.One way to use this is to pass in the results of
Elements.getElements(com.google.inject.Module...)
as theelements
parameter.This differs from
getEntries()
in that it will return duplicates if they are present in theelements
passed in. This does not run the normal Guice de-duplication thatgetEntries()
does.- Throws:
IllegalArgumentException
- if the provided elements contain partial map entries. If the elements come fromElements.getElements(com.google.inject.Module...)
on a module with a MapBinder, there will be a 1:1 relationship and no exception will be thrown.- Since:
- 4.2
-
permitsDuplicates
boolean permitsDuplicates()
Returns true if the MapBinder permits duplicates. This is only supported on bindings returned from an injector. This will throwUnsupportedOperationException
if it is called on a MapBinderBinding retrieved fromElements.getElements(com.google.inject.Module...)
.
-
containsElement
boolean containsElement(Element element)
Returns true if this MapBinder contains the given Element in order to build the map or uses the given Element in order to support building and injecting the map. This will work for MapBinderBindings retrieved from an injector andElements.getElements(com.google.inject.Module...)
. Usually this is only necessary if you are working with elements retrieved from modules (without an Injector), otherwisegetEntries()
andpermitsDuplicates()
are better options.If you need to introspect the details of the map, such as the keys, values or if it permits duplicates, it is necessary to pass the elements through an Injector and use
getEntries()
andpermitsDuplicates()
.
-
-