Top Description Inners Fields Constructors Methods
com.google.common.reflect

public final Class ImmutableTypeToInstanceMap<B>

extends ForwardingMap<TypeToken<? extends B>, B>
implements TypeToInstanceMap<B>
Class Inheritance
All Implemented Interfaces
com.google.common.reflect.TypeToInstanceMap, java.util.Map
Annotations
@ElementTypesAreNonnullByDefault
Imports
com.google.common.collect.ForwardingMap, .ImmutableMap, com.google.errorprone.annotations.CanIgnoreReturnValue, .DoNotCall, java.util.Map, javax.annotation.CheckForNull

A type-to-instance map backed by an ImmutableMap. See also MutableTypeToInstanceMap.
Author
Ben Yu
Since
13.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ImmutableTypeToInstanceMap.Builder<B>

A builder for creating immutable type-to-instance maps.

Field Summary

Modifier and TypeField and Description
private final ImmutableMap<TypeToken<? extends B>, B>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <B> ImmutableTypeToInstanceMap.Builder<B>
builder()

Returns a new builder.

protected Map<TypeToken<? extends B>, B>
delegate()

Implements abstract com.google.common.collect.ForwardingMap.delegate.

Returns the backing delegate instance that methods are forwarded to.
public <T extends B> T
getInstance(TypeToken<T> type)

Implements com.google.common.reflect.TypeToInstanceMap.getInstance.

Returns the value the specified type is mapped to, or null if no entry for this type is present.
public <T extends B> T
getInstance(Class<T> type)

Implements com.google.common.reflect.TypeToInstanceMap.getInstance.

Returns the value the specified class is mapped to, or null if no entry for this class is present.
public static <B> ImmutableTypeToInstanceMap<B>
of()

Hides java.util.Map.of.

Returns an empty type to instance map.
public B
put(TypeToken<? extends B>
key with which the specified value is to be associated
key
,
B
value to be associated with the specified key
value
)

Overrides com.google.common.collect.ForwardingMap.put.

Implements java.util.Map.put.

Deprecated unsupported operation
Guaranteed to throw an exception and leave the map unmodified.
public void
putAll(Map<? extends TypeToken<? extends B>, ? extends B>
mappings to be stored in this map
map
)

Overrides com.google.common.collect.ForwardingMap.putAll.

Implements java.util.Map.putAll.

Deprecated unsupported operation
Guaranteed to throw an exception and leave the map unmodified.
public <T extends B> T
putInstance(TypeToken<T> type, T value)

Implements com.google.common.reflect.TypeToInstanceMap.putInstance.

Deprecated unsupported operation
Guaranteed to throw an exception and leave the map unmodified.
public <T extends B> T
putInstance(Class<T> type, T value)

Implements com.google.common.reflect.TypeToInstanceMap.putInstance.

Deprecated unsupported operation
Guaranteed to throw an exception and leave the map unmodified.
private <T extends B> T
Inherited from com.google.common.collect.ForwardingMap:
clearcontainsKeycontainsValueentrySetequalsgethashCodeisEmptykeySetremovesizestandardClearstandardContainsKeystandardContainsValuestandardEqualsstandardHashCodestandardIsEmptystandardPutAllstandardRemovestandardToStringvalues

Field Detail

delegateback to summary
private final ImmutableMap<TypeToken<? extends B>, B> delegate

Constructor Detail

ImmutableTypeToInstanceMapback to summary
private ImmutableTypeToInstanceMap(ImmutableMap<TypeToken<? extends B>, B> delegate)

Method Detail

builderback to summary
public static <B> ImmutableTypeToInstanceMap.Builder<B> builder()

Returns a new builder.

delegateback to summary
protected Map<TypeToken<? extends B>, B> delegate()

Implements abstract com.google.common.collect.ForwardingMap.delegate.

Doc from com.google.common.collect.ForwardingObject.delegate.

Returns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such as ForwardingSet#delegate. Concrete subclasses override this method to supply the instance being decorated.

Annotations
@Override
getInstanceback to summary
public <T extends B> T getInstance(TypeToken<T> type)

Implements com.google.common.reflect.TypeToInstanceMap.getInstance.

Doc from com.google.common.reflect.TypeToInstanceMap.getInstance.

Returns the value the specified type is mapped to, or null if no entry for this type is present. This will only return a value that was bound to this specific type, not a value that may have been bound to a subtype.

Annotations
@Override
@CheckForNull
getInstanceback to summary
public <T extends B> T getInstance(Class<T> type)

Implements com.google.common.reflect.TypeToInstanceMap.getInstance.

Doc from com.google.common.reflect.TypeToInstanceMap.getInstance.

Returns the value the specified class is mapped to, or null if no entry for this class is present. This will only return a value that was bound to this specific class, not a value that may have been bound to a subtype.

getInstance(Foo.class) is equivalent to getInstance(TypeToken.of(Foo.class)).

Annotations
@Override
@CheckForNull
ofback to summary
public static <B> ImmutableTypeToInstanceMap<B> of()

Hides java.util.Map.of.

Returns an empty type to instance map.

Parameters
<B>

Doc from java.util.Map.of. the Map's key type

Returns:ImmutableTypeToInstanceMap<B>

Doc from java.util.Map.of.

an empty Map

putback to summary
public B put(TypeToken<? extends B> key, B value)

Overrides com.google.common.collect.ForwardingMap.put.

Implements java.util.Map.put.

Deprecated

unsupported operation

Guaranteed to throw an exception and leave the map unmodified.

Parameters
key:TypeToken<? extends B>

Doc from java.util.Map.put.

key with which the specified value is to be associated

value:B

Doc from java.util.Map.put.

value to be associated with the specified key

Returns:B

Doc from java.util.Map.put.

the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key, if the implementation supports null values.)

Annotations
@CanIgnoreReturnValue
@Deprecated
@Override
@DoNotCall:Always throws UnsupportedOperationException
@CheckForNull
Exceptions
UnsupportedOperationException:
always
putAllback to summary
public void putAll(Map<? extends TypeToken<? extends B>, ? extends B> map)

Overrides com.google.common.collect.ForwardingMap.putAll.

Implements java.util.Map.putAll.

Deprecated

unsupported operation

Guaranteed to throw an exception and leave the map unmodified.

Parameters
map:Map<? extends TypeToken<? extends B>, ? extends B>

Doc from java.util.Map.putAll.

mappings to be stored in this map

Annotations
@Deprecated
@Override
@DoNotCall:Always throws UnsupportedOperationException
Exceptions
UnsupportedOperationException:
always
putInstanceback to summary
public <T extends B> T putInstance(TypeToken<T> type, T value)

Implements com.google.common.reflect.TypeToInstanceMap.putInstance.

Deprecated

unsupported operation

Guaranteed to throw an exception and leave the map unmodified.

Returns:T

Doc from com.google.common.reflect.TypeToInstanceMap.putInstance.

the value previously associated with this type (possibly null), or null if there was no previous entry.

Annotations
@CanIgnoreReturnValue
@Deprecated
@Override
@DoNotCall:Always throws UnsupportedOperationException
@CheckForNull
Exceptions
UnsupportedOperationException:
always
putInstanceback to summary
public <T extends B> T putInstance(Class<T> type, T value)

Implements com.google.common.reflect.TypeToInstanceMap.putInstance.

Deprecated

unsupported operation

Guaranteed to throw an exception and leave the map unmodified.

Returns:T

Doc from com.google.common.reflect.TypeToInstanceMap.putInstance.

the value previously associated with this class (possibly null), or null if there was no previous entry.

Annotations
@CanIgnoreReturnValue
@Deprecated
@Override
@DoNotCall:Always throws UnsupportedOperationException
@CheckForNull
Exceptions
UnsupportedOperationException:
always
trustedGetback to summary
private <T extends B> T trustedGet(TypeToken<T> type)
Annotations
@SuppressWarnings:unchecked
@CheckForNull
com.google.common.reflect back to summary

public final Class ImmutableTypeToInstanceMap.Builder<B>

extends Object
Class Inheritance

A builder for creating immutable type-to-instance maps. Example:
static final ImmutableTypeToInstanceMap<Handler<?>> HANDLERS =
    ImmutableTypeToInstanceMap.<Handler<?>>builder()
        .put(new TypeToken<Handler<Foo>>() {}, new FooHandler())
        .put(new TypeToken<Handler<Bar>>() {}, new SubBarHandler())
        .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
13.0

Field Summary

Modifier and TypeField and Description
private final ImmutableMap.Builder<TypeToken<? extends B>, B>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public ImmutableTypeToInstanceMap<B>
build()

Returns a new immutable type-to-instance map containing the entries provided to this builder.

public <T extends B> ImmutableTypeToInstanceMap.Builder<B>
put(Class<T> key, T value)

Associates key with value in the built map.

public <T extends B> ImmutableTypeToInstanceMap.Builder<B>
put(TypeToken<T> key, T value)

Associates key with value in the built map.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mapBuilderback to summary
private final ImmutableMap.Builder<TypeToken<? extends B>, B> mapBuilder

Constructor Detail

Builderback to summary
private Builder()

Method Detail

buildback to summary
public ImmutableTypeToInstanceMap<B> build()

Returns a new immutable type-to-instance map containing the entries provided to this builder.

Exceptions
IllegalArgumentException:
if duplicate keys were added
putback to summary
public <T extends B> ImmutableTypeToInstanceMap.Builder<B> put(Class<T> key, T value)

Associates key with value in the built map. Duplicate keys are not allowed, and will cause build to fail.

Annotations
@CanIgnoreReturnValue
putback to summary
public <T extends B> ImmutableTypeToInstanceMap.Builder<B> put(TypeToken<T> key, T value)

Associates key with value in the built map. Duplicate keys are not allowed, and will cause build to fail.

Annotations
@CanIgnoreReturnValue