• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Guava Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.common.collect;
18 
19 import com.google.common.annotations.GwtCompatible;
20 import com.google.errorprone.annotations.CanIgnoreReturnValue;
21 import java.util.Collection;
22 import java.util.Map;
23 import java.util.Map.Entry;
24 import java.util.Set;
25 import javax.annotation.CheckForNull;
26 import org.checkerframework.checker.nullness.qual.Nullable;
27 
28 /**
29  * A multimap which forwards all its method calls to another multimap. Subclasses should override
30  * one or more methods to modify the behavior of the backing multimap as desired per the <a
31  * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
32  *
33  * <p><b>{@code default} method warning:</b> This class does <i>not</i> forward calls to {@code
34  * default} methods. Instead, it inherits their default implementations. When those implementations
35  * invoke methods, they invoke methods on the {@code ForwardingMultimap}.
36  *
37  * @author Robert Konigsberg
38  * @since 2.0
39  */
40 @GwtCompatible
41 @ElementTypesAreNonnullByDefault
42 public abstract class ForwardingMultimap<K extends @Nullable Object, V extends @Nullable Object>
43     extends ForwardingObject implements Multimap<K, V> {
44 
45   /** Constructor for use by subclasses. */
ForwardingMultimap()46   protected ForwardingMultimap() {}
47 
48   @Override
delegate()49   protected abstract Multimap<K, V> delegate();
50 
51   @Override
asMap()52   public Map<K, Collection<V>> asMap() {
53     return delegate().asMap();
54   }
55 
56   @Override
clear()57   public void clear() {
58     delegate().clear();
59   }
60 
61   @Override
containsEntry(@heckForNull Object key, @CheckForNull Object value)62   public boolean containsEntry(@CheckForNull Object key, @CheckForNull Object value) {
63     return delegate().containsEntry(key, value);
64   }
65 
66   @Override
containsKey(@heckForNull Object key)67   public boolean containsKey(@CheckForNull Object key) {
68     return delegate().containsKey(key);
69   }
70 
71   @Override
containsValue(@heckForNull Object value)72   public boolean containsValue(@CheckForNull Object value) {
73     return delegate().containsValue(value);
74   }
75 
76   @Override
entries()77   public Collection<Entry<K, V>> entries() {
78     return delegate().entries();
79   }
80 
81   @Override
get(@arametricNullness K key)82   public Collection<V> get(@ParametricNullness K key) {
83     return delegate().get(key);
84   }
85 
86   @Override
isEmpty()87   public boolean isEmpty() {
88     return delegate().isEmpty();
89   }
90 
91   @Override
keys()92   public Multiset<K> keys() {
93     return delegate().keys();
94   }
95 
96   @Override
keySet()97   public Set<K> keySet() {
98     return delegate().keySet();
99   }
100 
101   @CanIgnoreReturnValue
102   @Override
put(@arametricNullness K key, @ParametricNullness V value)103   public boolean put(@ParametricNullness K key, @ParametricNullness V value) {
104     return delegate().put(key, value);
105   }
106 
107   @CanIgnoreReturnValue
108   @Override
putAll(@arametricNullness K key, Iterable<? extends V> values)109   public boolean putAll(@ParametricNullness K key, Iterable<? extends V> values) {
110     return delegate().putAll(key, values);
111   }
112 
113   @CanIgnoreReturnValue
114   @Override
putAll(Multimap<? extends K, ? extends V> multimap)115   public boolean putAll(Multimap<? extends K, ? extends V> multimap) {
116     return delegate().putAll(multimap);
117   }
118 
119   @CanIgnoreReturnValue
120   @Override
remove(@heckForNull Object key, @CheckForNull Object value)121   public boolean remove(@CheckForNull Object key, @CheckForNull Object value) {
122     return delegate().remove(key, value);
123   }
124 
125   @CanIgnoreReturnValue
126   @Override
removeAll(@heckForNull Object key)127   public Collection<V> removeAll(@CheckForNull Object key) {
128     return delegate().removeAll(key);
129   }
130 
131   @CanIgnoreReturnValue
132   @Override
replaceValues(@arametricNullness K key, Iterable<? extends V> values)133   public Collection<V> replaceValues(@ParametricNullness K key, Iterable<? extends V> values) {
134     return delegate().replaceValues(key, values);
135   }
136 
137   @Override
size()138   public int size() {
139     return delegate().size();
140   }
141 
142   @Override
values()143   public Collection<V> values() {
144     return delegate().values();
145   }
146 
147   @Override
equals(@heckForNull Object object)148   public boolean equals(@CheckForNull Object object) {
149     return object == this || delegate().equals(object);
150   }
151 
152   @Override
hashCode()153   public int hashCode() {
154     return delegate().hashCode();
155   }
156 }
157