public static final class ImmutableClassToInstanceMap.Builder<B>
extends java.lang.Object
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.
Modifier and Type | Field and Description |
---|---|
private ImmutableMap.Builder<java.lang.Class<? extends B>,B> |
mapBuilder |
Constructor and Description |
---|
Builder() |
Modifier and Type | Method and Description |
---|---|
ImmutableClassToInstanceMap<B> |
build()
Returns a new immutable class-to-instance map containing the entries provided to this
builder.
|
private static <B,T extends B> |
cast(java.lang.Class<T> type,
B value) |
<T extends B> |
put(java.lang.Class<T> key,
T value)
Associates
key with value in the built map. |
<T extends B> |
putAll(java.util.Map<? extends java.lang.Class<? extends T>,? extends T> map)
Associates all of
map's keys and values in the built map. |
private final ImmutableMap.Builder<java.lang.Class<? extends B>,B> mapBuilder
public <T extends B> ImmutableClassToInstanceMap.Builder<B> put(java.lang.Class<T> key, T value)
key
with value
in the built map. Duplicate keys are not allowed,
and will cause build()
to fail.public <T extends B> ImmutableClassToInstanceMap.Builder<B> putAll(java.util.Map<? extends java.lang.Class<? extends T>,? extends T> map)
map's
keys and values in the built map. Duplicate keys are not
allowed, and will cause build()
to fail.java.lang.NullPointerException
- if any key or value in map
is nulljava.lang.ClassCastException
- if any value is not an instance of the type specified by its keyprivate static <B,T extends B> T cast(java.lang.Class<T> type, B value)
public ImmutableClassToInstanceMap<B> build()
java.lang.IllegalArgumentException
- if duplicate keys were added