001    /*
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package org.apache.commons.collections;
018    
019    import java.util.Collection;
020    import java.util.Map;
021    import java.util.Set;
022    
023    /** 
024     * <p>This <code>Map</code> wraps another <code>Map</code>
025     * implementation, using the wrapped instance for its default
026     * implementation.  This class is used as a framework on which to
027     * build to extensions for its wrapped <code>Map</code> object which
028     * would be unavailable or inconvenient via sub-classing (but usable
029     * via composition).</p>
030     * 
031     * <p>This implementation does not perform any special processing with
032     * {@link #entrySet()}, {@link #keySet()} or {@link #values()}. Instead
033     * it simply returns the set/collection from the wrapped map. This may be
034     * undesirable, for example if you are trying to write a validating
035     * implementation it would provide a loophole around the validation. But,
036     * you might want that loophole, so this class is kept simple.</p>
037     *
038     * @deprecated Moved to map subpackage as AbstractMapDecorator. It will be removed in v4.0.
039     * @since Commons Collections 2.0
040     * @version $Revision: 646777 $ $Date: 2008-04-10 13:33:15 +0100 (Thu, 10 Apr 2008) $
041     * 
042     * @author Daniel Rall
043     * @author Stephen Colebourne
044     */
045    public abstract class ProxyMap implements Map {
046        
047        /**
048         * The <code>Map</code> to delegate to.
049         */
050        protected Map map;
051    
052        /**
053         * Constructor that uses the specified map to delegate to.
054         * <p>
055         * Note that the map is used for delegation, and is not copied. This is
056         * different to the normal use of a <code>Map</code> parameter in
057         * collections constructors.
058         *
059         * @param map  the <code>Map</code> to delegate to
060         */
061        public ProxyMap(Map map) {
062            this.map = map;
063        }
064    
065        /**
066         * Invokes the underlying {@link Map#clear()} method.
067         */
068        public void clear() {
069            map.clear();
070        }
071    
072        /**
073         * Invokes the underlying {@link Map#containsKey(Object)} method.
074         */
075        public boolean containsKey(Object key) {
076            return map.containsKey(key);
077        }
078    
079        /**
080         * Invokes the underlying {@link Map#containsValue(Object)} method.
081         */
082        public boolean containsValue(Object value) {
083            return map.containsValue(value);
084        }
085    
086        /**
087         * Invokes the underlying {@link Map#entrySet()} method.
088         */
089        public Set entrySet() {
090            return map.entrySet();
091        }
092    
093        /**
094         * Invokes the underlying {@link Map#equals(Object)} method.
095         */
096        public boolean equals(Object m) {
097            return map.equals(m);
098        }
099    
100        /**
101         * Invokes the underlying {@link Map#get(Object)} method.
102         */
103        public Object get(Object key) {
104            return map.get(key);
105        }
106    
107        /**
108         * Invokes the underlying {@link Map#hashCode()} method.
109         */
110        public int hashCode() {
111            return map.hashCode();
112        }
113    
114        /**
115         * Invokes the underlying {@link Map#isEmpty()} method.
116         */
117        public boolean isEmpty() {
118            return map.isEmpty();
119        }
120    
121        /**
122         * Invokes the underlying {@link Map#keySet()} method.
123         */
124        public Set keySet() {
125            return map.keySet();
126        }
127    
128        /**
129         * Invokes the underlying {@link Map#put(Object,Object)} method.
130         */
131        public Object put(Object key, Object value) {
132            return map.put(key, value);
133        }
134    
135        /**
136         * Invokes the underlying {@link Map#putAll(Map)} method.
137         */
138        public void putAll(Map t) {
139            map.putAll(t);
140        }
141    
142        /**
143         * Invokes the underlying {@link Map#remove(Object)} method.
144         */
145        public Object remove(Object key) {
146            return map.remove(key);
147        }
148    
149        /**
150         * Invokes the underlying {@link Map#size()} method.
151         */
152        public int size() {
153            return map.size();
154        }
155    
156        /**
157         * Invokes the underlying {@link Map#values()} method.
158         */
159        public Collection values() {
160            return map.values();
161        }
162       
163    }