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