Class ForwardingMap<K extends @Nullable java.lang.Object,​V extends @Nullable java.lang.Object>

  • All Implemented Interfaces:
    java.util.Map<K,​V>
    Direct Known Subclasses:
    EnumBiMap, EnumHashBiMap, ForwardingConcurrentMap, ForwardingNavigableMap.StandardDescendingMap, ForwardingSortedMap, ImmutableClassToInstanceMap, ImmutableTypeToInstanceMap, MutableClassToInstanceMap, MutableTypeToInstanceMap

    @GwtCompatible
    public abstract class ForwardingMap<K extends @Nullable java.lang.Object,​V extends @Nullable java.lang.Object>
    extends ForwardingObject
    implements java.util.Map<K,​V>
    A map which forwards all its method calls to another map. Subclasses should override one or more methods to modify the behavior of the backing map as desired per the decorator pattern.

    Warning: The methods of ForwardingMap forward indiscriminately to the methods of the delegate. For example, overriding put(K, V) alone will not change the behavior of putAll(java.util.Map<? extends K, ? extends V>), which can lead to unexpected behavior. In this case, you should override putAll as well, either providing your own implementation, or delegating to the provided standardPutAll method.

    default method warning: This class does not forward calls to default methods. Instead, it inherits their default implementations. When those implementations invoke methods, they invoke methods on the ForwardingMap.

    Each of the standard methods, where appropriate, use Objects.equals(java.lang.Object, java.lang.Object) to test equality for both keys and values. This may not be the desired behavior for map implementations that use non-standard notions of key equality, such as a SortedMap whose comparator is not consistent with equals.

    The standard methods and the collection views they return are not guaranteed to be thread-safe, even when all of the methods that they depend on are thread-safe.

    Since:
    2.0
    Author:
    Kevin Bourrillion, Jared Levy, Louis Wasserman
    • Constructor Detail

      • ForwardingMap

        protected ForwardingMap()
        Constructor for use by subclasses.
    • Method Detail

      • delegate

        protected abstract java.util.Map<K,​V> 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 ForwardingObject
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<K extends @Nullable java.lang.Object,​V extends @Nullable java.lang.Object>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<K extends @Nullable java.lang.Object,​V extends @Nullable java.lang.Object>
      • remove

        @CanIgnoreReturnValue
        public @Nullable V remove​(@Nullable java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<K extends @Nullable java.lang.Object,​V extends @Nullable java.lang.Object>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<K extends @Nullable java.lang.Object,​V extends @Nullable java.lang.Object>
      • containsKey

        public boolean containsKey​(@Nullable java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<K extends @Nullable java.lang.Object,​V extends @Nullable java.lang.Object>
      • containsValue

        public boolean containsValue​(@Nullable java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<K extends @Nullable java.lang.Object,​V extends @Nullable java.lang.Object>
      • get

        public @Nullable V get​(@Nullable java.lang.Object key)
        Specified by:
        get in interface java.util.Map<K extends @Nullable java.lang.Object,​V extends @Nullable java.lang.Object>
      • put

        @CanIgnoreReturnValue
        public @Nullable V put​(K key,
                               V value)
        Specified by:
        put in interface java.util.Map<K extends @Nullable java.lang.Object,​V extends @Nullable java.lang.Object>
      • putAll

        public void putAll​(java.util.Map<? extends K,​? extends V> map)
        Specified by:
        putAll in interface java.util.Map<K extends @Nullable java.lang.Object,​V extends @Nullable java.lang.Object>
      • keySet

        public java.util.Set<K> keySet()
        Specified by:
        keySet in interface java.util.Map<K extends @Nullable java.lang.Object,​V extends @Nullable java.lang.Object>
      • values

        public java.util.Collection<V> values()
        Specified by:
        values in interface java.util.Map<K extends @Nullable java.lang.Object,​V extends @Nullable java.lang.Object>
      • entrySet

        public java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<K extends @Nullable java.lang.Object,​V extends @Nullable java.lang.Object>
      • equals

        public boolean equals​(@Nullable java.lang.Object object)
        Specified by:
        equals in interface java.util.Map<K extends @Nullable java.lang.Object,​V extends @Nullable java.lang.Object>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map<K extends @Nullable java.lang.Object,​V extends @Nullable java.lang.Object>
        Overrides:
        hashCode in class java.lang.Object
      • standardClear

        protected void standardClear()
        A sensible definition of clear() in terms of the iterator method of entrySet(). In many cases, you may wish to override clear() to forward to this implementation.
        Since:
        7.0