|
Generated by JDiff |
||||||||
PREV PACKAGE NEXT PACKAGE FRAMES NO FRAMES |
This file contains all the changes in documentation in the packagecom.google.inject.multibindings
as colored differences. Deletions are shownlike this, and additions are shown like this.
If no deletions or additions are shown in an entry, the HTML tags will be what has changed. The new HTML tags are shown in the differences. If no documentation existed, and then some was added in a later version, this change is noted in the appropriate class pages of differences, but the change is not shown on this page. Only changes in existing text are shown here. Similarly, documentation which was inherited from another class or interface is not shown here.
Note that an HTML error in the new documentation may cause the display of other documentation changes to be presented incorrectly. For instance, failure to close a <code> tag will cause all subsequent paragraphs to be displayed differently.
An API to bind multiple map entries separately, only to later inject themClass MapBinder, LinkedBindingBuilder<V> addBinding(K)asas a complete map. MapBinder is intended for use in your application's module:public class SnacksModule extends AbstractModule { protected void configure() { MapBinder<String, Snack> mapbinder = MapBinder.newMapBinder(binder(), String.class, Snack.class); mapbinder.addBinding("twix").toInstance(new Twix()); mapbinder.addBinding("snickers").toProvider(SnickersProvider.class); mapbinder.addBinding("skittles").to(Skittles.class); } }
With this binding, a Map{@code
} can now bebe injected:class SnackMachine { {@literal @}Inject public SnackMachine(Map<String, Snack> snacks) { ... } }
In addition to binding {@code Map
}, a mapbinder will also bindbind {@code Map>} for lazy value provision: class SnackMachine { {@literal @}Inject public SnackMachine(Map<String, Provider<Snack>> snackProviders) { ... } }
Contributing mapbindings from different modules is supported. For example,
it is okay tohavehave both {@code CandyModule} and {@code ChipsModule}bothboth create their own {@code MapBinder}, and to each contributecontribute bindings to the snacks map. When that map is injected, itwill containwill contain entries from both modules.The map's iteration order is consistent with the binding order. This
isis convenientwhenwhen multiple elements are contributed by the same modulebecausebecause that module can order itsbindingsbindings appropriately. Avoid relying onthethe iteration order of elements contributed by different modules, since thereisis no equivalent mechanism to order modules.The map is unmodifiable.
Elements can only be added to the mapbyby configuring the MapBinder.Elements can never be removed from the map.Values are resolved at map injection time. If a value is bound to
aa provider, that provider'ss get method will be called each time the mapisis injected (unless the binding is also scoped, oraa map of providers is injected).Annotations are used to create different maps of the same key/
valuevalue type. Eachdistinctdistinct annotation gets its own independent map.Keys must be distinct. If the same key is bound more
thanthan once, mapinjectioninjection will fail. However, use .permitDuplicates()inin order to allow duplicate keys;extraextra bindings to {@code Map>} andand {@code Map>} will be added. Keys must be non-null. {@code addBinding(null)}
willwill throw anuncheckedunchecked exception.Values must be non-null to use map injection. If
anyany value is null,mapmap injection will fail (although injecting a map ofprovidersproviders will not). @author dpb@google.com (David P. Baker)
Returns a binding builder used to add a new entry in the map.Class MapBinder, MapBinder<K, V> newMapBinder(Binder, Class<K>, Class<V>)EachEach key must be distinct (andand non-null). Bound providers will be evaluatedeacheach time the map is injected.It is an error to call this method without also calling one of
thethe {@code to} methods onthethe returned binding builder.Scoping elements independently is supported. Use the {@code in}
methodmethod to specify abindingbinding scope.
Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} inClass MapBinder, MapBinder<K, V> newMapBinder(Binder, Class<K>, Class<V>, Annotation)aa Map that is itself bound with no binding annotation.
Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} inClass MapBinder, MapBinder<K, V> newMapBinder(Binder, Class<K>, Class<V>, Class<Annotation>)aa Map that is itself bound with {@code annotation}.
Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} inClass MapBinder, MapBinder<K, V> newMapBinder(Binder, TypeLiteral<K>, TypeLiteral<V>)aa Map that is itself bound with {@code annotationType}.
Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} inClass MapBinder, MapBinder<K, V> newMapBinder(Binder, TypeLiteral<K>, TypeLiteral<V>, Annotation)aa Map that is itself bound with no binding annotation.
Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} inClass MapBinder, MapBinder<K, V> newMapBinder(Binder, TypeLiteral<K>, TypeLiteral<V>, Class<Annotation>)aa Map that is itself bound with {@code annotation}.
Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} inClass MapBinder, MapBinder<K, V> permitDuplicates()aa Map that is itself bound with {@code annotationType}.
Configures the {@code MapBinder} to handle duplicate entries.When multiple equal keys are bound, the value that gets included in the map
isis arbitrary.In addition to the {@code Map
} and {@code Map >} maps that arenormallynormally bound, a {@code Map>} andand {@code Map>>} are also bound, which containcontain all values bound to each key.
When multiple modules contribute elements to the map, thisconfigurationconfiguration option impactsallall of them. @return this map binder @since 3.0
A binding for a MapBinder.Class MapBinderBinding, boolean containsElement(Element)
Although MapBinders may be injected through a variety of generic types (Map<K, V>, Map <K, Provider<V>>, Map<K, Set<V>>, Map>, and eveneven Set<Map.Entry<K, Provider<V>>),aa MapBinderBinding exists only on the Bindingassociatedassociated with the Map<K, V> key.OtherOther bindings can be validated to be derived fromthisthis MapBinderBindingusingusing .containsElement(Element).@paramThe fully qualified type of the map, including Map. For example: MapBinderBinding<Map<String, Snack>>
@since 3.0 @author sameb@google.com (Sam Berlin)
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 and Elements.getElements. Usually this is only necessary if you are working with elements retrieved from modules (without an Injector), otherwise .getEntries and .permitsDuplicates are better options.Class MapBinderBinding, List<Entry<?, Binding<?>>> getEntries()
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 anduseuse .getEntries() and .permitsDuplicates().
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 willClass MapBinderBinding, TypeLiteral<?> getKeyTypeLiteral()throwthrow UnsupportedOperationException if it is called on an element retrievedfromfrom Elements.getElements.
The elements will always match the type Map's generic type. For example, ifgetMapKeygetMapKey returnsaa key ofMap<String, Snack>
, then this will always return a listof typeof typeList<Map.Entry<String, Binding<Snack>>>
.
Returns the TypeLiteral describing the keys of the map.Class MapBinderBinding, TypeLiteral<?> getValueTypeLiteral()
The TypeLiteral will always match the type Map's generic type. For example, if getMapKey returns a key ofMap<String, Snack>
, then this will always returnaaTypeLiteral<String>
.
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 ofMap<String, Snack>
, then this will always returnaaTypeLiteral<Snack>
.
Allows users define customized key type annotations for map bindings by annotating an annotation of a {@code Map}'s key type. The custom key annotation can be applied to methods also annotated with {@literal @}ProvidesIntoMap.A StringMapKey and ClassMapKey are provided for convenience with maps whose keys are strings or classes. For maps with enums or primitive types as keys, you must provide your own MapKey annotation, such as this one for an enum:
{@literal @}MapKey(unwrapValue = true) {@literal @}Retention(RUNTIME) public {@literal @}interface MyCustomEnumKey { MyCustomEnum value(); }You can also use the whole annotation as the key, if {@code unwrapValue=false}.WhenunwrapValueunwrapValue is false, the annotation type will be the key type for the injected mapandand theannotationannotation instances will be the key values. If {@code unwrapValue=true}, the value()typetype will be thekeykey type for injected map and the value() instances will be the keys values. @since 4.0
An API to bind multiple values separately, only to later inject them asClass Multibinder, LinkedBindingBuilder<T> addBinding()aa complete collection. Multibinder is intended for use in your application'ss module:public class SnacksModule extends AbstractModule { protected void configure() { Multibinder<Snack> multibinder = Multibinder.newSetBinder(binder(), Snack.class); multibinder.addBinding().toInstance(new Twix()); multibinder.addBinding().toProvider(SnickersProvider.class); multibinder.addBinding().to(Skittles.class); } }
With this binding, a Set{@code
} can now be injected: If desired, Collection{@codeclass SnackMachine { {@literal @}Inject public SnackMachine(Set<Snack> snacks) { ... } }
>} can also be injected. Contributing multibindings from different modules is supported.
ForFor example, it is okayforfor both {@code CandyModule} and {@code ChipsModule}to create their own {@code Multibinder}, and to each contributecontribute bindings to the set of snacks. When that set is injected, it will contain elements from both modules.The set's iteration order is consistent with the binding order. This
isis convenientwhenwhen multiple elements are contributed by the same modulebecausebecause that module can order itsbindingsbindings appropriately. Avoid relying onthethe iteration order of elements contributed by different modules, since thereisis no equivalent mechanism to order modules.The set is unmodifiable.
Elements can only be added to the setbyby configuring the multibinder.Elements can never be removed from the set.Elements are resolved at set injection time. If an element is bound to
aa provider,thatthat provider's get method will be called each time the setisis injected (unless the binding isalsoalso scoped).Annotations are be used to create different sets of the same
elementelement type. Eachdistinctdistinct annotation gets its own independent collectionofof elements.Elements must be distinct. If multiple bound
elementselements have the same value, set injection will fail.Elements must be non-null. If any set element is null,
set injectionwillwill fail. @author jessewilson@google.com (Jesse Wilson)
Returns a binding builder used to add a new element in the set.EachEach bound element must haveaa distinct value. Bound providers willbebe evaluated each time the set is injected.It is an error to call this method without also calling one of
thethe {@code to} methods onthethe returned binding builder.Scoping elements independently is supported. Use the {@code in}
methodmethod to specify abindingbinding scope.
A binding for a Multibinder.Class MultibinderBinding, boolean containsElement(Element)@paramThe fully qualified type of the set, including Set. For example: MultibinderBinding<Set<Boolean>>
@since 3.0 @author sameb@google.com (Sam Berlin)
Returns true if this Multibinder uses the given Element. This will be true for bindings that derive the elements of the set and other bindings that Multibinder uses internally. This will work for MultibinderBindings retrieved from an injector and Elements.getElements. Usually this is only necessary if you are working with elements retrieved from modules (without an Injector), otherwise .getElements and .permitsDuplicates are better options.Class MultibinderBinding, TypeLiteral<?> getElementTypeLiteral()
If you need to introspect the details of the set, such as the values or if it permits duplicates, it is necessary to pass the elements through an Injector anduseuse .getElements() and .permitsDuplicates().
Returns the TypeLiteral that describes the type of elements in the set.Class MultibinderBinding, List<Binding<?>> getElements()
The elements will always match the type Set's generic type. For example, ifgetSetKeygetSetKey returnsaa key ofSet<String>
, then this will always returnaaTypeLiteral<String>
.
Returns all bindings that make up the set. This is only supported on bindings returned from an injector. This will throw UnsupportedOperationException if it is called on an element retrieved from Elements.getElements.
The elements will always match the type Set's generic type. For example, ifgetSetKeygetSetKey returnsaa key ofSet<String>
, then this will always return a list of typeList<Binding<String>>
.
Scans a module for annotations that signal multibindings, mapbindings, and optional bindings. @since 4.Class MultibindingsScanner, Module asModule()00 @deprecated This functionality is installed by default. All references to this can be safely removed. This class will be removed in Guice 4.4
Returns a module that, when installed, will scan all modules for methods with the annotations {@literal @}ProvidesIntoMap, {@literal @}ProvidesIntoSet, and {@literal @}ProvidesIntoOptional.Class MultibindingsScanner, ModuleAnnotatedMethodScanner scanner()This is a convenience method, equivalent to
doingdoing {@codecode binder().scanModulesForAnnotatedMethods(MultibindingsScanner.scanner())}. @deprecated This functionality is now installed by default. All references/installations can be eliminated.
Returns a ModuleAnnotatedMethodScanner that,@deprecatedwhenThisbound,methodwill scan all modules for methods with the annotationsreturns an empty scanner since the preexisting functionality is{@literal@}ProvidesIntoMap,{@literal@}ProvidesIntoSet,andinstalled{@literalby@}ProvidesIntoOptionaldefault.
A visitor for the multibinder extension.Class MultibindingsTargetVisitor, V visit(OptionalBinderBinding<? extends T>)
If your BindingTargetVisitor implements this interface, bindings created by using Multibinder, MapBinder or OptionalBinderBinding will be visited through this interface. @since 3.0 @author sameb@google.com (Sam Berlin)
Visits a binding created through OptionalBinder.@since 4.0
An API to bind optional values, optionally with a default value.Class OptionalBinder, LinkedBindingBuilder<T> setBinding()OptionalBinder fulfillstwotwo roles:
- It allows a framework to define an injection point that may
oror may not be bound by users.- It allows a framework to supply a default value that can be
changedchangedby users.When an OptionalBinder is added, it will always supply the bindings:
{@code Optional} andand {@code Optional>}. IfIf .setBinding or .setDefault are called, itwill alsowill also bind {@code T}.{@code setDefault} is intended for use by frameworks that need a
defaultdefault value.User codecancan call {@code setBinding} to override the default.Warning: Even if setBinding is called,thethe defaultbindingbinding will still exist in the object graph.If it is a singleton, it will be instantiated in {@code Stage.PRODUCTION}.If setDefault or setBinding are linked to Providers, the Provider may
returnreturn {@code null}.IfIf it does, the Optional bindings will be absent.BindingBinding setBinding to a Provider that returnsnullnull will not causeOptionalBinderOptionalBinder to fall back to the setDefault binding.If neither setDefault nor setBinding are called, it will try to link to
aa user-suppliedsupplied binding of the same type.If no binding exists, theoptionalsoptionals will be absent.Otherwise, ifaa user-supplied binding of that type exists,or if setBinding or setDefault are called,thethe optionals will returnpresentpresent if they are bound to a non-null value.Values are resolved at injection time. If a value is bound to
aa provider, that provider'sgetget method will be called each time theoptionaloptional is injected (unless the binding is also scoped,oror an optional of providerisis injected).Annotations are used to create different optionals of the same key/
valuevalue type. Eachdistinctdistinct annotation gets its own independent binding.public class FrameworkModule extends AbstractModule { protected void configure() { OptionalBinder.newOptionalBinder(binder(), Renamer.class); } }
With this module, an Optional{@code
} can now bebe injected.With nootherother bindings, the optional will be absent.Users can specify bindings in one of two ways:Option 1:
public class UserRenamerModule extends AbstractModule { protected void configure() { bind(Renamer.class).to(ReplacingRenamer.class); } }
or Option 2:
public class UserRenamerModule extends AbstractModule { protected void configure() { OptionalBinder.newOptionalBinder(binder(), Renamer.class) .setBinding().to(ReplacingRenamer.class); } }
With both options, the {@code Optional} will be present and supply thethe ReplacingRenamer.Default values can be supplied using:
public class FrameworkModule extends AbstractModule { protected void configure() { OptionalBinder.newOptionalBinder(binder(), Key.get(String.class, LookupUrl.class)) .setDefault().toInstance(DEFAULT_LOOKUP_URL); } }
With the above module, code can inject an {@code @LookupUrl String} anditit will supplythethe DEFAULT_LOOKUP_URL.A user can change this value bybindingbindingpublic class UserLookupModule extends AbstractModule { protected void configure() { OptionalBinder.newOptionalBinder(binder(), Key.get(String.class, LookupUrl.class)) .setBinding().toInstance(CUSTOM_LOOKUP_URL); } }
... which will override the default value.If one module uses setDefault the only way to override the default is to use setBinding.
Itisis an error for a user to specify the binding without using OptionalBinderifif setDefaultoror setBinding are called.For example,public class FrameworkModule extends AbstractModule { protected void configure() { OptionalBinder.newOptionalBinder(binder(), Key.get(String.class, LookupUrl.class)) .setDefault().toInstance(DEFAULT_LOOKUP_URL); } } public class UserLookupModule extends AbstractModule { protected void configure() { bind(Key.get(String.class, LookupUrl.class)).toInstance(CUSTOM_LOOKUP_URL); }
}... would generate an error, because both the framework and the user are trying to bind {@code @LookupUrl String}.@author sameb@google.com (Sam Berlin) @since 4.0
Returns a binding builder used to set the actual value that will be injected.Class OptionalBinder, LinkedBindingBuilder<T> setDefault()Thisoverridesoverrides any binding set by .setDefault.It is an error to call this method without also calling one of the {@code to}
methods onthethe returned binding builder.
Returns a binding builder used to set the default value that will be injected.The bindingsetset by this method will be ignored if .setBinding is called.It is an error to call this method without also calling one of the {@code to}
methods onthethe returned binding builder.
A binding for a OptionalBinder.Class OptionalBinderBinding, boolean containsElement(Element)Although OptionalBinders may be injected through a variety of
typestypes {@code T}, {@codecode Optional}, {@code Optional >}, etc..), anan OptionalBinderBinding exists only onthethe Binding associated withthethe {@code Optional} key. Other bindings can be validated tobebe derived fromthisthis OptionalBinderBinding using .containsElement.@paramThe fully qualified type of the optional binding, including Optional. For example:Forexample:{@code Optional}. @since 4.0 @author sameb@google.com (Sam Berlin)
Returns true if this OptionalBinder contains the given Element in order to build the optional binding or uses the given Element in order to support building and injecting its data. This will work for OptionalBinderBinding retrieved from an injectorClass OptionalBinderBinding, Binding<?> getActualBinding()andand Elements.getElements. Usually this is only necessary if you are working with elements retrieved from modules (without an Injector), otherwise .getDefaultBindingandand .getActualBinding are better options.
Returns the actual binding (set by OptionalBinder.setBinding) or null if not set.Class OptionalBinderBinding, Binding<?> getDefaultBinding()ThisThis will throw UnsupportedOperationException if it is called on an elementretrievedretrievedfromfrom Elements.getElements.
The Binding's type will always match the type Optional's generic type. For example,if getKeyif getKey returns a key ofOptional<String>
, then this will always returnaaBinding<String>
.
Returns the default binding (set by OptionalBinder.setDefault) if one exists ornull ifnull if no default binding is set. This will throw UnsupportedOperationException if it is called on an element retrieved from Elements.getElements.
The Binding's type will always match the type Optional's generic type. For example,if getKeyif getKey returns a key ofOptional<String>
, then this will always returnaaBinding<String>
.
Annotates methods of a Module to add items to a MapBinder.The method'sreturnreturn type, binding annotation and additional key annotationdeterminesdetermines what Map this willcontributecontribute to. For example,{@literal @}ProvidesIntoMap {@literal @}StringMapKey("Foo") {@literal @}Named("will add two items to the {@code @Named("urls") Mappluginsurls") Plugin provideFooUrl(FooManager fm) { return fm.getPlugin(); } {@literal @}ProvidesIntoMap {@literal @}StringMapKey("Bar") {@literal @}Named("urls") Plugin provideBarUrl(BarManager bm) { return bm.getPlugin(); }} map. The key 'Foo' willmapmap to the provideFooUrl method, and the key 'Bar' will map to the provideBarUrl method.Thevaluesvalues are bound as providers and will be evaluated at injection time.Because the key is specified as an annotation, only Strings, Classes, enums,
primitiveprimitivetypestypes and annotation instances are supported as keys. @author sameb@google.com (Sam Berlin) @since 4.0
Annotates methods of a Module to add items to a Multibinder.The method'sreturnreturn type and binding annotation determines what Optional thiswillwill contribute to. For example,{@literal @}ProvidesIntoOptional(DEFAULT) {@literal @}Named("url") String provideFooUrl(FooManager fm) { returm fm.getUrl(); } {@literal @}ProvidesIntoOptional(ACTUAL) {@literal @}Named("url") String provideBarUrl(BarManager bm) { return bm.getUrl(); }will set the default value of {@code @Named("url") Optional} to foo's URL, andthenthen override it to bar's URL. @author sameb@google.com (Sam Berlin) @since 4.0
Annotates methods of a Module to add items to a Multibinder.The method'sreturnreturn type and binding annotation determines what Set thiswillwill contribute to. For example,{@literal @}ProvidesIntoSet {@literal @}Named("urls") String provideFooUrl(FooManager fm) { returm fm.getUrl(); } {@literal @}ProvidesIntoSet {@literal @}Named("urls") String provideBarUrl(BarManager bm) { return bm.getUrl(); }will add two items to the {@code @Named("urls") Set} set. The items are bound as providers and will be evaluated at injection time. @author sameb@google.com (Sam Berlin) @since 4.0