Class ImmutableClassToInstanceMap.Builder<B>
java.lang.Object
com.google.common.collect.ImmutableClassToInstanceMap.Builder<B>
- Enclosing class:
- ImmutableClassToInstanceMap<B>
A builder for creating immutable class-to-instance maps. Example:
 
 
static final ImmutableClassToInstanceMap<Handler> HANDLERS =
    new ImmutableClassToInstanceMap.Builder<Handler>()
        .put(FooHandler.class, new FooHandler())
        .put(BarHandler.class, new SubBarHandler())
        .put(Handler.class, new QuuxHandler())
        .build();
After invoking build() it is still possible to add more entries and build again.
 Thus each map generated by this builder will be a superset of any map generated before it.
- Since:
- 2.0
- Author:
- Kevin Bourrillion
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionbuild()Returns a new immutable class-to-instance map containing the entries provided to this builder.<T extends B>
 ImmutableClassToInstanceMap.Builder<B> Associateskeywithvaluein the built map.<T extends B>
 ImmutableClassToInstanceMap.Builder<B> Associates all ofmap'skeys and values in the built map.
- 
Constructor Details- 
Builderpublic Builder()Creates a new builder.
 
- 
- 
Method Details- 
put@CanIgnoreReturnValue public <T extends B> ImmutableClassToInstanceMap.Builder<B> put(Class<T> key, T value) Associateskeywithvaluein the built map. Duplicate keys are not allowed, and will causebuild()to fail.
- 
putAll@CanIgnoreReturnValue public <T extends B> ImmutableClassToInstanceMap.Builder<B> putAll(Map<? extends Class<? extends T>, ? extends T> map) Associates all ofmap'skeys and values in the built map. Duplicate keys are not allowed, and will causebuild()to fail.- Throws:
- NullPointerException- if any key or value in- mapis null
- ClassCastException- if any value is not an instance of the type specified by its key
 
- 
buildReturns a new immutable class-to-instance map containing the entries provided to this builder.- Throws:
- IllegalArgumentException- if duplicate keys were added
 
 
-