KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > binding > collection > SharedMapDecorator


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package org.springframework.binding.collection;
17
18 import java.io.Serializable JavaDoc;
19 import java.util.Collection JavaDoc;
20 import java.util.Map JavaDoc;
21 import java.util.Set JavaDoc;
22
23 import org.springframework.core.style.ToStringCreator;
24
25 /**
26  * A map decorator that implements <code>SharedMap</code>. By default, simply
27  * returns the map itself as the mutex. Subclasses may override to return a
28  * different mutex object.
29  *
30  * @author Keith Donald
31  */

32 public class SharedMapDecorator implements SharedMap, Serializable JavaDoc {
33
34     /**
35      * The wrapped, target map.
36      */

37     private Map JavaDoc map;
38
39     /**
40      * Creates a new shared map decorator.
41      * @param map the map that is shared by multiple threads, to be synced
42      */

43     public SharedMapDecorator(Map JavaDoc map) {
44         this.map = map;
45     }
46     
47     // implementing Map
48

49     public void clear() {
50         map.clear();
51     }
52
53     public boolean containsKey(Object JavaDoc key) {
54         return map.containsKey(key);
55     }
56
57     public boolean containsValue(Object JavaDoc value) {
58         return map.containsValue(value);
59     }
60
61     public Set JavaDoc entrySet() {
62         return map.entrySet();
63     }
64
65     public Object JavaDoc get(Object JavaDoc key) {
66         return map.get(key);
67     }
68
69     public boolean isEmpty() {
70         return map.isEmpty();
71     }
72
73     public Set JavaDoc keySet() {
74         return map.keySet();
75     }
76
77     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
78         return map.put(key, value);
79     }
80
81     public void putAll(Map JavaDoc map) {
82         this.map.putAll(map);
83     }
84
85     public Object JavaDoc remove(Object JavaDoc key) {
86         return map.remove(key);
87     }
88
89     public int size() {
90         return map.size();
91     }
92
93     public Collection JavaDoc values() {
94         return map.values();
95     }
96     
97     // implementing SharedMap
98

99     public Object JavaDoc getMutex() {
100         return map;
101     }
102
103     public String JavaDoc toString() {
104         return new ToStringCreator(this).append("map", map).append("mutex", getMutex()).toString();
105     }
106 }
Popular Tags