KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > map > AbstractMapDecorator


1 /*
2  * Copyright 2003-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.map;
17
18 import java.util.Collection JavaDoc;
19 import java.util.Map JavaDoc;
20 import java.util.Set JavaDoc;
21
22 /**
23  * Provides a base decorator that enables additional functionality to be added
24  * to a Map via decoration.
25  * <p>
26  * Methods are forwarded directly to the decorated map.
27  * <p>
28  * This implementation does not perform any special processing with
29  * {@link #entrySet()}, {@link #keySet()} or {@link #values()}. Instead
30  * it simply returns the set/collection from the wrapped map. This may be
31  * undesirable, for example if you are trying to write a validating
32  * implementation it would provide a loophole around the validation.
33  * But, you might want that loophole, so this class is kept simple.
34  *
35  * @since Commons Collections 3.0
36  * @version $Revision: 1.5 $ $Date: 2004/04/02 21:02:54 $
37  *
38  * @author Daniel Rall
39  * @author Stephen Colebourne
40  */

41 public abstract class AbstractMapDecorator implements Map JavaDoc {
42
43     /** The map to decorate */
44     protected transient Map JavaDoc map;
45
46     /**
47      * Constructor only used in deserialization, do not use otherwise.
48      * @since Commons Collections 3.1
49      */

50     protected AbstractMapDecorator() {
51         super();
52     }
53
54     /**
55      * Constructor that wraps (not copies).
56      *
57      * @param map the map to decorate, must not be null
58      * @throws IllegalArgumentException if the collection is null
59      */

60     public AbstractMapDecorator(Map JavaDoc map) {
61         if (map == null) {
62             throw new IllegalArgumentException JavaDoc("Map must not be null");
63         }
64         this.map = map;
65     }
66
67     /**
68      * Gets the map being decorated.
69      *
70      * @return the decorated map
71      */

72     protected Map JavaDoc getMap() {
73         return map;
74     }
75
76     //-----------------------------------------------------------------------
77
public void clear() {
78         map.clear();
79     }
80
81     public boolean containsKey(Object JavaDoc key) {
82         return map.containsKey(key);
83     }
84
85     public boolean containsValue(Object JavaDoc value) {
86         return map.containsValue(value);
87     }
88
89     public Set JavaDoc entrySet() {
90         return map.entrySet();
91     }
92
93     public Object JavaDoc get(Object JavaDoc key) {
94         return map.get(key);
95     }
96
97     public boolean isEmpty() {
98         return map.isEmpty();
99     }
100
101     public Set JavaDoc keySet() {
102         return map.keySet();
103     }
104
105     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
106         return map.put(key, value);
107     }
108
109     public void putAll(Map JavaDoc mapToCopy) {
110         map.putAll(mapToCopy);
111     }
112
113     public Object JavaDoc remove(Object JavaDoc key) {
114         return map.remove(key);
115     }
116
117     public int size() {
118         return map.size();
119     }
120
121     public Collection JavaDoc values() {
122         return map.values();
123     }
124    
125     public boolean equals(Object JavaDoc object) {
126         if (object == this) {
127             return true;
128         }
129         return map.equals(object);
130     }
131
132     public int hashCode() {
133         return map.hashCode();
134     }
135
136     public String JavaDoc toString() {
137         return map.toString();
138     }
139
140 }
141
Popular Tags