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, Provider<V>>, Map<K, Set<V>>, Map
>, and even Set<Map.Entry<K, Provider<V>>), a MapBinderBinding exists only on the Binding associated with the Map<K, V> key. Other bindings can be validated to be derived from this MapBinderBinding using containsElement(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.java.util.List<java.util.Map.Entry<?,Binding<?>>>
getEntries()
Returns all entries in the Map.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
-
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
java.util.List<java.util.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>>>
.
-
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()
.
-
-