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
041public abstract class ForwardingMultimap<K extends @Nullable Object, V extends @Nullable Object>
042    extends ForwardingObject implements Multimap<K, V> {
043
044  /** Constructor for use by subclasses. */
045  protected ForwardingMultimap() {}
046
047  @Override
048  protected abstract Multimap<K, V> delegate();
049
050  @Override
051  public Map<K, Collection<V>> asMap() {
052    return delegate().asMap();
053  }
054
055  @Override
056  public void clear() {
057    delegate().clear();
058  }
059
060  @Override
061  public boolean containsEntry(@CheckForNull Object key, @CheckForNull Object value) {
062    return delegate().containsEntry(key, value);
063  }
064
065  @Override
066  public boolean containsKey(@CheckForNull Object key) {
067    return delegate().containsKey(key);
068  }
069
070  @Override
071  public boolean containsValue(@CheckForNull Object value) {
072    return delegate().containsValue(value);
073  }
074
075  @Override
076  public Collection<Entry<K, V>> entries() {
077    return delegate().entries();
078  }
079
080  @Override
081  public Collection<V> get(@ParametricNullness K key) {
082    return delegate().get(key);
083  }
084
085  @Override
086  public boolean isEmpty() {
087    return delegate().isEmpty();
088  }
089
090  @Override
091  public Multiset<K> keys() {
092    return delegate().keys();
093  }
094
095  @Override
096  public Set<K> keySet() {
097    return delegate().keySet();
098  }
099
100  @CanIgnoreReturnValue
101  @Override
102  public boolean put(@ParametricNullness K key, @ParametricNullness V value) {
103    return delegate().put(key, value);
104  }
105
106  @CanIgnoreReturnValue
107  @Override
108  public boolean putAll(@ParametricNullness K key, Iterable<? extends V> values) {
109    return delegate().putAll(key, values);
110  }
111
112  @CanIgnoreReturnValue
113  @Override
114  public boolean putAll(Multimap<? extends K, ? extends V> multimap) {
115    return delegate().putAll(multimap);
116  }
117
118  @CanIgnoreReturnValue
119  @Override
120  public boolean remove(@CheckForNull Object key, @CheckForNull Object value) {
121    return delegate().remove(key, value);
122  }
123
124  @CanIgnoreReturnValue
125  @Override
126  public Collection<V> removeAll(@CheckForNull Object key) {
127    return delegate().removeAll(key);
128  }
129
130  @CanIgnoreReturnValue
131  @Override
132  public Collection<V> replaceValues(@ParametricNullness K key, Iterable<? extends V> values) {
133    return delegate().replaceValues(key, values);
134  }
135
136  @Override
137  public int size() {
138    return delegate().size();
139  }
140
141  @Override
142  public Collection<V> values() {
143    return delegate().values();
144  }
145
146  @Override
147  public boolean equals(@CheckForNull Object object) {
148    return object == this || delegate().equals(object);
149  }
150
151  @Override
152  public int hashCode() {
153    return delegate().hashCode();
154  }
155}