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