1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.springframework.osgi.util.internal;
17
18 import java.util.Collection;
19 import java.util.Dictionary;
20 import java.util.Enumeration;
21 import java.util.Iterator;
22 import java.util.LinkedHashMap;
23 import java.util.Map;
24 import java.util.Set;
25
26 import org.springframework.util.Assert;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 public class MapBasedDictionary extends Dictionary implements Map {
46
47 private Map map;
48
49
50
51
52
53
54
55 private static class IteratorBasedEnumeration implements Enumeration {
56
57 private Iterator it;
58
59 public IteratorBasedEnumeration(Iterator it) {
60 Assert.notNull(it);
61 this.it = it;
62 }
63
64 public IteratorBasedEnumeration(Collection col) {
65 this(col.iterator());
66 }
67
68 public boolean hasMoreElements() {
69 return it.hasNext();
70 }
71
72 public Object nextElement() {
73 return it.next();
74 }
75
76 }
77
78 public MapBasedDictionary(Map map) {
79 this.map = (map == null ? new LinkedHashMap() : map);
80 }
81
82
83
84
85
86 public MapBasedDictionary() {
87 this.map = new LinkedHashMap();
88 }
89
90 public MapBasedDictionary(int initialCapacity) {
91 this.map = new LinkedHashMap(initialCapacity);
92 }
93
94
95
96
97
98
99
100 public MapBasedDictionary(Dictionary dictionary) {
101 this(new LinkedHashMap(), dictionary);
102 }
103
104 public MapBasedDictionary(Map map, Dictionary dictionary) {
105 this(map);
106 if (dictionary != null)
107 putAll(dictionary);
108 }
109
110 public void clear() {
111 map.clear();
112 }
113
114 public boolean containsKey(Object key) {
115 return map.containsKey(key);
116 }
117
118 public boolean containsValue(Object value) {
119 return map.containsValue(value);
120 }
121
122 public Set entrySet() {
123 return map.entrySet();
124 }
125
126 public Object get(Object key) {
127 if (key == null)
128 throw new NullPointerException();
129 return map.get(key);
130 }
131
132 public boolean isEmpty() {
133 return map.isEmpty();
134 }
135
136 public Set keySet() {
137 return map.keySet();
138 }
139
140 public Object put(Object key, Object value) {
141 if (key == null || value == null)
142 throw new NullPointerException();
143
144 return map.put(key, value);
145 }
146
147 public void putAll(Map t) {
148 map.putAll(t);
149 }
150
151 public void putAll(Dictionary dictionary) {
152 if (dictionary != null)
153
154 for (Enumeration enm = dictionary.keys(); enm.hasMoreElements();) {
155 Object key = enm.nextElement();
156 map.put(key, dictionary.get(key));
157 }
158 }
159
160 public Object remove(Object key) {
161 if (key == null)
162 throw new NullPointerException();
163
164 return map.remove(key);
165 }
166
167 public int size() {
168 return map.size();
169 }
170
171 public Collection values() {
172 return map.values();
173 }
174
175 public Enumeration elements() {
176 return new IteratorBasedEnumeration(map.values());
177 }
178
179 public Enumeration keys() {
180 return new IteratorBasedEnumeration(map.keySet());
181 }
182
183 public String toString() {
184 return map.toString();
185 }
186
187 public boolean equals(Object obj) {
188
189
190 return map.equals(obj);
191 }
192
193 public int hashCode() {
194 return map.hashCode();
195 }
196
197 }