Class MutableClassToInstanceMap<B>

java.lang.Object
com.google.common.collect.ForwardingObject
com.google.common.collect.ForwardingMap<Class<? extends B>,B>
com.google.common.collect.MutableClassToInstanceMap<B>
All Implemented Interfaces:
ClassToInstanceMap<B>, Serializable, Map<Class<? extends B>,B>

public final class MutableClassToInstanceMap<B> extends ForwardingMap<Class<? extends B>,B> implements ClassToInstanceMap<B>, Serializable
A mutable class-to-instance map backed by an arbitrary user-provided map. See also ImmutableClassToInstanceMap.

See the Guava User Guide article on ClassToInstanceMap.

Since:
2.0
See Also:
  • Field Details

    • delegate

      private final Map<Class<? extends B>,B> delegate
  • Constructor Details

    • MutableClassToInstanceMap

      private MutableClassToInstanceMap(Map<Class<? extends B>,B> delegate)
  • Method Details

    • create

      public static <B> MutableClassToInstanceMap<B> create()
      Returns a new MutableClassToInstanceMap instance backed by a HashMap using the default initial capacity and load factor.
    • create

      public static <B> MutableClassToInstanceMap<B> create(Map<Class<? extends 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.
    • delegate

      protected Map<Class<? extends B>,B> delegate()
      Description copied from class: ForwardingObject
      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.
      Specified by:
      delegate in class ForwardingMap<Class<? extends B>,B>
    • checkedEntry

      private static <B> Map.Entry<Class<? extends B>,B> checkedEntry(Map.Entry<Class<? extends B>,B> entry)
      Wraps the setValue implementation of an Entry to enforce the class constraint.
    • entrySet

      public Set<Map.Entry<Class<? extends B>,B>> entrySet()
      Specified by:
      entrySet in interface Map<Class<? extends B>,B>
      Overrides:
      entrySet in class ForwardingMap<Class<? extends B>,B>
    • put

      @CheckForNull public B put(Class<? extends B> key, B value)
      Specified by:
      put in interface Map<Class<? extends B>,B>
      Overrides:
      put in class ForwardingMap<Class<? extends B>,B>
    • putAll

      public void putAll(Map<? extends Class<? extends B>,? extends B> map)
      Specified by:
      putAll in interface Map<Class<? extends B>,B>
      Overrides:
      putAll in class ForwardingMap<Class<? extends B>,B>
    • putInstance

      @CheckForNull public <T extends B> T putInstance(Class<T> type, T value)
      Description copied from interface: ClassToInstanceMap
      Maps the specified class to the specified value. Does not associate this value with any of the class's supertypes.
      Specified by:
      putInstance in interface ClassToInstanceMap<B>
      Returns:
      the value previously associated with this class (possibly null), or null if there was no previous entry.
    • getInstance

      @CheckForNull public <T extends B> T getInstance(Class<T> type)
      Description copied from interface: ClassToInstanceMap
      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.
      Specified by:
      getInstance in interface ClassToInstanceMap<B>
    • cast

      @CheckForNull private static <T> T cast(Class<T> type, @CheckForNull Object value)
    • writeReplace

      private Object writeReplace()
    • readObject

      private void readObject(ObjectInputStream stream) throws InvalidObjectException
      Throws:
      InvalidObjectException