1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.morph.util;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 /**
22 * A map where all keys and values are of type {@link java.lang.Class}. This is
23 * accomplished by making the {@link #put(Object, Object)}method convert the
24 * key and value supplied to it to a <code>Class</code> object using
25 * {@link net.sf.morph.util.ClassUtils#newInstance(Object)}. This class is
26 * included to ease the configuration of Morph. One example of where it is used
27 * is in
28 * {@link net.sf.morph.reflect.reflectors.SimpleInstantiatingReflector#setRequestedToInstantiatedTypeMap(Map)}.
29 *
30 * @author Matt Sgarlata
31 * @since Apr 14, 2005
32 */
33 public class TypeMap extends HashMap {
34
35 /**
36 * Create a new TypeMap.
37 */
38 public TypeMap() {
39 super();
40 }
41
42 /**
43 * Create a new TypeMap.
44 * @param initialCapacity
45 */
46 public TypeMap(int initialCapacity) {
47 super(initialCapacity);
48 }
49
50 /**
51 * Create a new TypeMap.
52 * @param initialCapacity
53 * @param loadFactor
54 */
55 public TypeMap(int initialCapacity, float loadFactor) {
56 super(initialCapacity, loadFactor);
57 }
58
59 /**
60 * Create a new TypeMap.
61 * @param map
62 */
63 public TypeMap(Map map) {
64 this(map.size());
65 putAll(map);
66 }
67
68 /**
69 * {@inheritDoc}
70 */
71 public Object put(Object key, Object value) {
72 return super.put(key == null ? null : ClassUtils.convertToClass(key),
73 value == null ? null : ClassUtils.convertToClass(value));
74 }
75
76 }