001    /*
002     * Copyright (C) 2007 Google Inc.
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    
017    package com.google.common.collect;
018    
019    import com.google.common.annotations.GwtCompatible;
020    
021    import java.util.Collection;
022    import java.util.Map;
023    import java.util.Set;
024    
025    import javax.annotation.Nullable;
026    
027    /**
028     * A map which forwards all its method calls to another map. Subclasses should
029     * override one or more methods to modify the behavior of the backing map as
030     * desired per the <a
031     * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
032     *
033     * @author Kevin Bourrillion
034     * @author Jared Levy
035     * @since 2 (imported from Google Collections Library)
036     */
037    @GwtCompatible
038    public abstract class ForwardingMap<K, V> extends ForwardingObject
039        implements Map<K, V> {
040    
041      /** Constructor for use by subclasses. */
042      protected ForwardingMap() {}
043    
044      @Override protected abstract Map<K, V> delegate();
045    
046      public int size() {
047        return delegate().size();
048      }
049    
050      public boolean isEmpty() {
051        return delegate().isEmpty();
052      }
053    
054      public V remove(Object object) {
055        return delegate().remove(object);
056      }
057    
058      public void clear() {
059        delegate().clear();
060      }
061    
062      public boolean containsKey(Object key) {
063        return delegate().containsKey(key);
064      }
065    
066      public boolean containsValue(Object value) {
067        return delegate().containsValue(value);
068      }
069    
070      public V get(Object key) {
071        return delegate().get(key);
072      }
073    
074      public V put(K key, V value) {
075        return delegate().put(key, value);
076      }
077    
078      public void putAll(Map<? extends K, ? extends V> map) {
079        delegate().putAll(map);
080      }
081    
082      public Set<K> keySet() {
083        return delegate().keySet();
084      }
085    
086      public Collection<V> values() {
087        return delegate().values();
088      }
089    
090      public Set<Entry<K, V>> entrySet() {
091        return delegate().entrySet();
092      }
093    
094      @Override public boolean equals(@Nullable Object object) {
095        return object == this || delegate().equals(object);
096      }
097    
098      @Override public int hashCode() {
099        return delegate().hashCode();
100      }
101    }