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;
022
023/**
024 * A concurrent map which forwards all its method calls to another concurrent map. Subclasses should
025 * override one or more methods to modify the behavior of the backing map as desired per the <a
026 * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
027 *
028 * <p><b>{@code default} method warning:</b> This class forwards calls to <i>only some</i> {@code
029 * default} methods. Specifically, it forwards calls only for methods that existed <a
030 * href="https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentMap.html">before
031 * {@code default} methods were introduced</a>. For newer methods, like {@code forEach}, it inherits
032 * their default implementations. When those implementations invoke methods, they invoke methods on
033 * the {@code ForwardingConcurrentMap}.
034 *
035 * @author Charles Fry
036 * @since 2.0
037 */
038@GwtCompatible
039public abstract class ForwardingConcurrentMap<K, V> extends ForwardingMap<K, V>
040    implements ConcurrentMap<K, V> {
041
042  /** Constructor for use by subclasses. */
043  protected ForwardingConcurrentMap() {}
044
045  @Override
046  protected abstract ConcurrentMap<K, V> delegate();
047
048  @CanIgnoreReturnValue
049  @Override
050  public V putIfAbsent(K key, V value) {
051    return delegate().putIfAbsent(key, value);
052  }
053
054  @CanIgnoreReturnValue
055  @Override
056  public boolean remove(Object key, Object value) {
057    return delegate().remove(key, value);
058  }
059
060  @CanIgnoreReturnValue
061  @Override
062  public V replace(K key, V value) {
063    return delegate().replace(key, value);
064  }
065
066  @CanIgnoreReturnValue
067  @Override
068  public boolean replace(K key, V oldValue, V newValue) {
069    return delegate().replace(key, oldValue, newValue);
070  }
071}