001/*
002 * Copyright (C) 2007 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.google.common.collect;
018
019import com.google.common.annotations.GwtCompatible;
020import com.google.errorprone.annotations.CanIgnoreReturnValue;
021import java.util.concurrent.ConcurrentMap;
022import javax.annotation.CheckForNull;
023
024/**
025 * A concurrent map which forwards all its method calls to another concurrent map. Subclasses should
026 * override one or more methods to modify the behavior of the backing map as desired per the <a
027 * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
028 *
029 * <p><b>{@code default} method warning:</b> This class forwards calls to <i>only some</i> {@code
030 * default} methods. Specifically, it forwards calls only for methods that existed <a
031 * href="https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentMap.html">before
032 * {@code default} methods were introduced</a>. For newer methods, like {@code forEach}, it inherits
033 * their default implementations. When those implementations invoke methods, they invoke methods on
034 * the {@code ForwardingConcurrentMap}.
035 *
036 * @author Charles Fry
037 * @since 2.0
038 */
039@GwtCompatible
040@ElementTypesAreNonnullByDefault
041public abstract class ForwardingConcurrentMap<K, V> extends ForwardingMap<K, V>
042    implements ConcurrentMap<K, V> {
043
044  /** Constructor for use by subclasses. */
045  protected ForwardingConcurrentMap() {}
046
047  @Override
048  protected abstract ConcurrentMap<K, V> delegate();
049
050  @CanIgnoreReturnValue
051  @Override
052  @CheckForNull
053  public V putIfAbsent(K key, V value) {
054    return delegate().putIfAbsent(key, value);
055  }
056
057  @CanIgnoreReturnValue
058  @Override
059  public boolean remove(@CheckForNull Object key, @CheckForNull Object value) {
060    return delegate().remove(key, value);
061  }
062
063  @CanIgnoreReturnValue
064  @Override
065  @CheckForNull
066  public V replace(K key, V value) {
067    return delegate().replace(key, value);
068  }
069
070  @CanIgnoreReturnValue
071  @Override
072  public boolean replace(K key, V oldValue, V newValue) {
073    return delegate().replace(key, oldValue, newValue);
074  }
075}