Home | History | Annotate | Download | only in collect
      1 /*
      2  * Copyright (C) 2007 Google Inc.
      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 
     21 import java.util.Collection;
     22 import java.util.Map;
     23 import java.util.Set;
     24 
     25 import javax.annotation.Nullable;
     26 
     27 /**
     28  * A map which forwards all its method calls to another map. Subclasses should
     29  * override one or more methods to modify the behavior of the backing map as
     30  * desired per the <a
     31  * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
     32  *
     33  * @see ForwardingObject
     34  * @author Kevin Bourrillion
     35  * @author Jared Levy
     36  * @since 2010.01.04 <b>stable</b> (imported from Google Collections Library)
     37  */
     38 @GwtCompatible
     39 public abstract class ForwardingMap<K, V> extends ForwardingObject
     40     implements Map<K, V> {
     41 
     42   @Override protected abstract Map<K, V> delegate();
     43 
     44   public int size() {
     45     return delegate().size();
     46   }
     47 
     48   public boolean isEmpty() {
     49     return delegate().isEmpty();
     50   }
     51 
     52   public V remove(Object object) {
     53     return delegate().remove(object);
     54   }
     55 
     56   public void clear() {
     57     delegate().clear();
     58   }
     59 
     60   public boolean containsKey(Object key) {
     61     return delegate().containsKey(key);
     62   }
     63 
     64   public boolean containsValue(Object value) {
     65     return delegate().containsValue(value);
     66   }
     67 
     68   public V get(Object key) {
     69     return delegate().get(key);
     70   }
     71 
     72   public V put(K key, V value) {
     73     return delegate().put(key, value);
     74   }
     75 
     76   public void putAll(Map<? extends K, ? extends V> map) {
     77     delegate().putAll(map);
     78   }
     79 
     80   public Set<K> keySet() {
     81     return delegate().keySet();
     82   }
     83 
     84   public Collection<V> values() {
     85     return delegate().values();
     86   }
     87 
     88   public Set<Entry<K, V>> entrySet() {
     89     return delegate().entrySet();
     90   }
     91 
     92   @Override public boolean equals(@Nullable Object object) {
     93     return object == this || delegate().equals(object);
     94   }
     95 
     96   @Override public int hashCode() {
     97     return delegate().hashCode();
     98   }
     99 }
    100