KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > ProxyMap


1 /*
2  * Copyright 2002-2004 The Apache Software Foundation
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 package org.apache.commons.collections;
17
18 import java.util.Collection JavaDoc;
19 import java.util.Map JavaDoc;
20 import java.util.Set JavaDoc;
21
22 /**
23  * <p>This <code>Map</code> wraps another <code>Map</code>
24  * implementation, using the wrapped instance for its default
25  * implementation. This class is used as a framework on which to
26  * build to extensions for its wrapped <code>Map</code> object which
27  * would be unavailable or inconvenient via sub-classing (but usable
28  * via composition).</p>
29  *
30  * <p>This implementation does not perform any special processing with
31  * {@link #entrySet()}, {@link #keySet()} or {@link #values()}. Instead
32  * it simply returns the set/collection from the wrapped map. This may be
33  * undesirable, for example if you are trying to write a validating
34  * implementation it would provide a loophole around the validation. But,
35  * you might want that loophole, so this class is kept simple.</p>
36  *
37  * @deprecated Moved to map subpackage as AbstractMapDecorator. It will be removed in v4.0.
38  * @since Commons Collections 2.0
39  * @version $Revision: 1.15 $ $Date: 2004/02/18 01:15:42 $
40  *
41  * @author Daniel Rall
42  * @author Stephen Colebourne
43  */

44 public abstract class ProxyMap implements Map JavaDoc {
45     
46     /**
47      * The <code>Map</code> to delegate to.
48      */

49     protected Map JavaDoc map;
50
51     /**
52      * Constructor that uses the specified map to delegate to.
53      * <p>
54      * Note that the map is used for delegation, and is not copied. This is
55      * different to the normal use of a <code>Map</code> parameter in
56      * collections constructors.
57      *
58      * @param map the <code>Map</code> to delegate to
59      */

60     public ProxyMap(Map JavaDoc map) {
61         this.map = map;
62     }
63
64     /**
65      * Invokes the underlying {@link Map#clear()} method.
66      */

67     public void clear() {
68         map.clear();
69     }
70
71     /**
72      * Invokes the underlying {@link Map#containsKey(Object)} method.
73      */

74     public boolean containsKey(Object JavaDoc key) {
75         return map.containsKey(key);
76     }
77
78     /**
79      * Invokes the underlying {@link Map#containsValue(Object)} method.
80      */

81     public boolean containsValue(Object JavaDoc value) {
82         return map.containsValue(value);
83     }
84
85     /**
86      * Invokes the underlying {@link Map#entrySet()} method.
87      */

88     public Set JavaDoc entrySet() {
89         return map.entrySet();
90     }
91
92     /**
93      * Invokes the underlying {@link Map#equals(Object)} method.
94      */

95     public boolean equals(Object JavaDoc m) {
96         return map.equals(m);
97     }
98
99     /**
100      * Invokes the underlying {@link Map#get(Object)} method.
101      */

102     public Object JavaDoc get(Object JavaDoc key) {
103         return map.get(key);
104     }
105
106     /**
107      * Invokes the underlying {@link Map#hashCode()} method.
108      */

109     public int hashCode() {
110         return map.hashCode();
111     }
112
113     /**
114      * Invokes the underlying {@link Map#isEmpty()} method.
115      */

116     public boolean isEmpty() {
117         return map.isEmpty();
118     }
119
120     /**
121      * Invokes the underlying {@link Map#keySet()} method.
122      */

123     public Set JavaDoc keySet() {
124         return map.keySet();
125     }
126
127     /**
128      * Invokes the underlying {@link Map#put(Object,Object)} method.
129      */

130     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
131         return map.put(key, value);
132     }
133
134     /**
135      * Invokes the underlying {@link Map#putAll(Map)} method.
136      */

137     public void putAll(Map JavaDoc t) {
138         map.putAll(t);
139     }
140
141     /**
142      * Invokes the underlying {@link Map#remove(Object)} method.
143      */

144     public Object JavaDoc remove(Object JavaDoc key) {
145         return map.remove(key);
146     }
147
148     /**
149      * Invokes the underlying {@link Map#size()} method.
150      */

151     public int size() {
152         return map.size();
153     }
154
155     /**
156      * Invokes the underlying {@link Map#values()} method.
157      */

158     public Collection JavaDoc values() {
159         return map.values();
160     }
161    
162 }
163
Popular Tags