T
- The fully qualified type of the map, including Map. For example:
MapBinderBinding<Map<String, Snack>>
public interface MapBinderBinding<T>
Although MapBinders may be injected through a variety of generic types (Map<K, V>, Map
<K, Provider<V>>, Map<K, Set<V>>, MapcontainsElement(Element)
.
Modifier and Type | Method and 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.
|
java.util.List<java.util.Map.Entry<?,Binding<?>>> |
getEntries(java.lang.Iterable<? extends Element> elements)
Similar to
getEntries() , but can be used on a MapBinderBinding retrieved from Elements.getElements(com.google.inject.Module...) . |
TypeLiteral<?> |
getKeyTypeLiteral()
Returns the TypeLiteral describing the keys of the map.
|
Key<T> |
getMapKey()
Returns the
Key for the map. |
TypeLiteral<?> |
getValueTypeLiteral()
Returns the TypeLiteral describing the values of the map.
|
boolean |
permitsDuplicates()
Returns true if the MapBinder permits duplicates.
|
TypeLiteral<?> getKeyTypeLiteral()
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 a
TypeLiteral<String>
.
TypeLiteral<?> getValueTypeLiteral()
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 a
TypeLiteral<Snack>
.
java.util.List<java.util.Map.Entry<?,Binding<?>>> getEntries()
UnsupportedOperationException
if it is called on an element retrieved from Elements.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
type List<Map.Entry<String, Binding<Snack>>>
.
java.util.List<java.util.Map.Entry<?,Binding<?>>> getEntries(java.lang.Iterable<? extends Element> elements)
getEntries()
, but can be used on a MapBinderBinding retrieved from Elements.getElements(com.google.inject.Module...)
.
One way to use this is to pass in the results of Elements.getElements(com.google.inject.Module...)
as the elements
parameter.
This differs from getEntries()
in that it will return duplicates if they are
present in the elements
passed in. This does not run the normal Guice de-duplication
that getEntries()
does.
java.lang.IllegalArgumentException
- if the provided elements contain partial map entries. If the
elements come from Elements.getElements(com.google.inject.Module...)
on a module with a MapBinder, there will be
a 1:1 relationship and no exception will be thrown.boolean permitsDuplicates()
UnsupportedOperationException
if it is called on a
MapBinderBinding retrieved from Elements.getElements(com.google.inject.Module...)
.boolean containsElement(Element element)
Elements.getElements(com.google.inject.Module...)
. Usually this is
only necessary if you are working with elements retrieved from modules (without an Injector),
otherwise getEntries()
and permitsDuplicates()
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()
and permitsDuplicates()
.