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.Collection;
022import java.util.Map;
023import java.util.Map.Entry;
024import java.util.Set;
025import org.checkerframework.checker.nullness.qual.Nullable;
026
027/**
028 * A multimap which forwards all its method calls to another multimap. Subclasses should override
029 * one or more methods to modify the behavior of the backing multimap as desired per the <a
030 * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
031 *
032 * <p><b>{@code default} method warning:</b> This class does <i>not</i> forward calls to {@code
033 * default} methods. Instead, it inherits their default implementations. When those implementations
034 * invoke methods, they invoke methods on the {@code ForwardingMultimap}.
035 *
036 * @author Robert Konigsberg
037 * @since 2.0
038 */
039@GwtCompatible
040public abstract class ForwardingMultimap<K, V> extends ForwardingObject implements Multimap<K, V> {
041
042  /** Constructor for use by subclasses. */
043  protected ForwardingMultimap() {}
044
045  @Override
046  protected abstract Multimap<K, V> delegate();
047
048  @Override
049  public Map<K, Collection<V>> asMap() {
050    return delegate().asMap();
051  }
052
053  @Override
054  public void clear() {
055    delegate().clear();
056  }
057
058  @Override
059  public boolean containsEntry(@Nullable Object key, @Nullable Object value) {
060    return delegate().containsEntry(key, value);
061  }
062
063  @Override
064  public boolean containsKey(@Nullable Object key) {
065    return delegate().containsKey(key);
066  }
067
068  @Override
069  public boolean containsValue(@Nullable Object value) {
070    return delegate().containsValue(value);
071  }
072
073  @Override
074  public Collection<Entry<K, V>> entries() {
075    return delegate().entries();
076  }
077
078  @Override
079  public Collection<V> get(@Nullable K key) {
080    return delegate().get(key);
081  }
082
083  @Override
084  public boolean isEmpty() {
085    return delegate().isEmpty();
086  }
087
088  @Override
089  public Multiset<K> keys() {
090    return delegate().keys();
091  }
092
093  @Override
094  public Set<K> keySet() {
095    return delegate().keySet();
096  }
097
098  @CanIgnoreReturnValue
099  @Override
100  public boolean put(K key, V value) {
101    return delegate().put(key, value);
102  }
103
104  @CanIgnoreReturnValue
105  @Override
106  public boolean putAll(K key, Iterable<? extends V> values) {
107    return delegate().putAll(key, values);
108  }
109
110  @CanIgnoreReturnValue
111  @Override
112  public boolean putAll(Multimap<? extends K, ? extends V> multimap) {
113    return delegate().putAll(multimap);
114  }
115
116  @CanIgnoreReturnValue
117  @Override
118  public boolean remove(@Nullable Object key, @Nullable Object value) {
119    return delegate().remove(key, value);
120  }
121
122  @CanIgnoreReturnValue
123  @Override
124  public Collection<V> removeAll(@Nullable Object key) {
125    return delegate().removeAll(key);
126  }
127
128  @CanIgnoreReturnValue
129  @Override
130  public Collection<V> replaceValues(K key, Iterable<? extends V> values) {
131    return delegate().replaceValues(key, values);
132  }
133
134  @Override
135  public int size() {
136    return delegate().size();
137  }
138
139  @Override
140  public Collection<V> values() {
141    return delegate().values();
142  }
143
144  @Override
145  public boolean equals(@Nullable Object object) {
146    return object == this || delegate().equals(object);
147  }
148
149  @Override
150  public int hashCode() {
151    return delegate().hashCode();
152  }
153}