1 package org.apache.ojb.broker.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21
22
23
24
25
26
27 public final class IdentityHashMap extends HashMap
28 {
29 private static final class IdentityKey
30 {
31 private final Object m_key;
32
33 public IdentityKey(final Object key)
34 {
35 m_key = key;
36 }
37
38 public boolean equals(final Object o)
39 {
40 return (o == m_key);
41 }
42
43 public int hashCode()
44 {
45 return System.identityHashCode(m_key);
46 }
47 }
48
49
50
51
52
53
54 public IdentityHashMap(final int initialCapacity, final float loadFactor)
55 {
56 super(initialCapacity, loadFactor);
57 }
58
59
60
61
62
63 public IdentityHashMap(final int initialCapacity)
64 {
65 super(initialCapacity);
66 }
67
68
69
70
71 public IdentityHashMap()
72 {
73 super();
74 }
75
76
77
78
79
80 public IdentityHashMap(final Map t)
81 {
82 super(t);
83 }
84
85
86
87
88 public Object get(final Object key)
89 {
90 return super.get(new IdentityKey(key));
91 }
92
93
94
95
96 public Object put(final Object key, final Object value)
97 {
98 return super.put(new IdentityKey(key), value);
99 }
100
101
102
103
104 public Object add(final Object value)
105 {
106 final Object key = new IdentityKey(value);
107 if (!super.containsKey(key))
108 {
109 return super.put(key, value);
110 }
111 else
112 {
113 return null;
114 }
115 }
116
117
118
119
120 public Object remove(final Object key)
121 {
122 return super.remove(new IdentityKey(key));
123 }
124
125
126
127
128 public boolean containsKey(final Object key)
129 {
130 return super.containsKey(new IdentityKey(key));
131 }
132 }
133