1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.directory.server.protocol.shared;
22
23
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.Dictionary;
27 import java.util.Enumeration;
28 import java.util.HashMap;
29 import java.util.HashSet;
30 import java.util.Hashtable;
31 import java.util.Iterator;
32 import java.util.Map;
33 import java.util.Set;
34
35
36
37
38
39
40
41
42
43 public class MapAdapter implements Map<Object, Object>
44 {
45 private Dictionary<Object, Object> dictionary;
46
47
48
49
50
51
52
53 public MapAdapter( Dictionary<Object, Object> dictionary )
54 {
55 this.dictionary = dictionary;
56 }
57
58
59
60
61
62 public void clear()
63 {
64 dictionary = new Hashtable<Object, Object>();
65 }
66
67
68
69
70
71 public boolean containsKey( Object key )
72 {
73 return Collections.list( dictionary.keys() ).contains( key );
74 }
75
76
77
78
79
80 public boolean containsValue( Object value )
81 {
82 return Collections.list( dictionary.elements() ).contains( value );
83 }
84
85
86
87
88
89 public Set<Map.Entry<Object, Object>> entrySet()
90 {
91 Map<Object, Object> map = new HashMap<Object, Object>();
92
93 Enumeration<Object> e = dictionary.keys();
94
95 while ( e.hasMoreElements() )
96 {
97 Object key = e.nextElement();
98 Object value = dictionary.get( key );
99 map.put( key, value );
100 }
101
102 return map.entrySet();
103 }
104
105
106
107
108
109 public Object get( Object key )
110 {
111 return dictionary.get( key );
112 }
113
114
115
116
117
118 public boolean isEmpty()
119 {
120 return dictionary.isEmpty();
121 }
122
123
124
125
126
127 public Set<Object> keySet()
128 {
129 return new HashSet<Object>( Collections.list( dictionary.keys() ) );
130 }
131
132
133
134
135
136 public Object put( Object arg0, Object arg1 )
137 {
138 return dictionary.put( arg0, arg1 );
139 }
140
141
142
143
144
145 public void putAll( Map arg0 )
146 {
147 Iterator it = arg0.entrySet().iterator();
148
149 while ( it.hasNext() )
150 {
151 Map.Entry entry = ( Map.Entry ) it.next();
152 dictionary.put( entry.getKey(), entry.getValue() );
153 }
154 }
155
156
157
158
159
160 public Object remove( Object key )
161 {
162 return dictionary.remove( key );
163 }
164
165
166
167
168
169 public int size()
170 {
171 return dictionary.size();
172 }
173
174
175
176
177
178 public Collection<Object> values()
179 {
180 return Collections.list( dictionary.elements() );
181 }
182 }