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

public final Class MutableClassToInstanceMap<B extends @Nullable Object>

extends ForwardingMap<Class<? extends @NonNull B extends @Nullable Object>, B extends @Nullable Object>
implements ClassToInstanceMap<B extends @Nullable Object>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, com.google.common.collect.ClassToInstanceMap, java.util.Map
Annotations
@J2ktIncompatible
@GwtIncompatible
@SuppressWarnings:serial
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkNotNull

A mutable class-to-instance map backed by an arbitrary user-provided map. See also ImmutableClassToInstanceMap.

See the Guava User Guide article on ClassToInstanceMap.

Author
Kevin Bourrillion
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
MutableClassToInstanceMap.SerializedForm<B extends @Nullable Object>

Serialized form of the map, to avoid serializing the constraint.

Field Summary

Modifier and TypeField and Description
private final Map<Class<? extends @NonNull B>, B>

Constructor Summary

AccessConstructor and Description
private
MutableClassToInstanceMap(Map<Class<? extends @NonNull B>, B> delegate)

Method Summary

Modifier and TypeMethod and Description
private static <T> T
cast(Class<T> type, Object value)

private static <B extends @Nullable Object> Map.Entry<Class<? extends @NonNull B>, B>
checkedEntry(final Map.Entry<Class<? extends @NonNull B>, B> entry)

Wraps the setValue implementation of an Entry to enforce the class constraint.

public static <B extends @Nullable Object> MutableClassToInstanceMap<B>
create()

Returns a new MutableClassToInstanceMap instance backed by a HashMap using the default initial capacity and load factor.

public static <B extends @Nullable Object> MutableClassToInstanceMap<B>
create(Map<Class<? extends @NonNull B>, B> backingMap)

Returns a new MutableClassToInstanceMap instance backed by a given empty backingMap.

protected Map<Class<? extends @NonNull B>, B>
delegate()

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

Returns the backing delegate instance that methods are forwarded to.
public Set<Map.Entry<Class<? extends @NonNull B>, B>>
entrySet()

Overrides com.google.common.collect.ForwardingMap.entrySet.

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.
public <T extends @NonNull B> T
getInstance(Class<T> type)

Implements com.google.common.collect.ClassToInstanceMap.getInstance.

Returns the value the specified class is mapped to, or null if no entry for this class is present.
public B
put(Class<? extends @NonNull 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.

Associates the specified value with the specified key in this map (optional operation).
public void
putAll(Map<? extends Class<? extends @NonNull B>, ? extends B>
mappings to be stored in this map
map
)

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

Implements java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation).
public <T extends B> T
putInstance(Class<@NonNull T> type, T value)

Implements com.google.common.collect.ClassToInstanceMap.putInstance.

Maps the specified class to the specified value.
private void
private Object
Inherited from com.google.common.collect.ForwardingMap:
clearcontainsKeycontainsValueequalsgethashCodeisEmptykeySetremovesizestandardClearstandardContainsKeystandardContainsValuestandardEqualsstandardHashCodestandardIsEmptystandardPutAllstandardRemovestandardToStringvalues

Field Detail

delegateback to summary
private final Map<Class<? extends @NonNull B>, B> delegate

Constructor Detail

MutableClassToInstanceMapback to summary
private MutableClassToInstanceMap(Map<Class<? extends @NonNull B>, B> delegate)

Method Detail

castback to summary
private static <T> T cast(Class<T> type, Object value)
Annotations
@CanIgnoreReturnValue
@CheckForNull
checkedEntryback to summary
private static <B extends @Nullable Object> Map.Entry<Class<? extends @NonNull B>, B> checkedEntry(final Map.Entry<Class<? extends @NonNull B>, B> entry)

Wraps the setValue implementation of an Entry to enforce the class constraint.

createback to summary
public static <B extends @Nullable Object> MutableClassToInstanceMap<B> create()

Returns a new MutableClassToInstanceMap instance backed by a HashMap using the default initial capacity and load factor.

createback to summary
public static <B extends @Nullable Object> MutableClassToInstanceMap<B> create(Map<Class<? extends @NonNull B>, B> backingMap)

Returns a new MutableClassToInstanceMap instance backed by a given empty backingMap. The caller surrenders control of the backing map, and thus should not allow any direct references to it to remain accessible.

delegateback to summary
protected Map<Class<? extends @NonNull 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
entrySetback to summary
public Set<Map.Entry<Class<? extends @NonNull B>, B>> entrySet()

Overrides com.google.common.collect.ForwardingMap.entrySet.

Implements java.util.Map.entrySet.

Doc from java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:Set<Map.Entry<Class<? extends @NonNull B>, B>>

a set view of the mappings contained in this map

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

Implements com.google.common.collect.ClassToInstanceMap.getInstance.

Doc from com.google.common.collect.ClassToInstanceMap.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.

Annotations
@Override
@CheckForNull
putback to summary
public B put(Class<? extends @NonNull B> key, B value)

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

Implements java.util.Map.put.

Doc from java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)

Parameters
key:Class<? extends @NonNull B>

key with which the specified value is to be associated

value:B

value to be associated with the specified key

Returns:B

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
@Override
@CanIgnoreReturnValue
@CheckForNull
putAllback to summary
public void putAll(Map<? extends Class<? extends @NonNull B>, ? extends B> map)

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

Implements java.util.Map.putAll.

Doc from java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation). The effect of this call is equivalent to that of calling put(k, v) on this map once for each mapping from key k to value v in the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress. If the specified map has a defined encounter order, processing of its mappings generally occurs in that order.

Parameters
map:Map<? extends Class<? extends @NonNull B>, ? extends B>

mappings to be stored in this map

Annotations
@Override
putInstanceback to summary
public <T extends B> T putInstance(Class<@NonNull T> type, T value)

Implements com.google.common.collect.ClassToInstanceMap.putInstance.

Doc from com.google.common.collect.ClassToInstanceMap.putInstance.

Maps the specified class to the specified value. Does not associate this value with any of the class's supertypes.

Returns:T

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

Annotations
@CanIgnoreReturnValue
@Override
@CheckForNull
readObjectback to summary
private void readObject(ObjectInputStream stream) throws InvalidObjectException
writeReplaceback to summary
private Object writeReplace()
com.google.common.collect back to summary

private final Class MutableClassToInstanceMap.SerializedForm<B extends @Nullable Object>

extends Object
implements Serializable
Class Inheritance
  • java.lang.Object
  • com.google.common.collect.MutableClassToInstanceMap.SerializedForm
All Implemented Interfaces
java.io.Serializable

Serialized form of the map, to avoid serializing the constraint.

Field Summary

Modifier and TypeField and Description
private final Map<Class<? extends @NonNull B>, B>
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv
SerializedForm(Map<Class<? extends @NonNull B>, B> backingMap)

Method Summary

Modifier and TypeMethod and Description
pack-priv Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

backingMapback to summary
private final Map<Class<? extends @NonNull B>, B> backingMap
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

SerializedFormback to summary
pack-priv SerializedForm(Map<Class<? extends @NonNull B>, B> backingMap)

Method Detail

readResolveback to summary
pack-priv Object readResolve()