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