KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > utils > IdentityHashMap


1 /**
2  * Created by IntelliJ IDEA.
3  * User: srida01
4  * Date: Dec 2, 2002
5  * Time: 10:38:46 AM
6  * To change this template use Options | File Templates.
7  */

8 package org.apache.axis.utils;
9
10 import java.util.HashMap JavaDoc;
11 import java.util.Map JavaDoc;
12
13 /**
14  * IdentityHashMap similar to JDK1.4's java.util.IdentityHashMap
15  * @author Davanum Srinivas <dims@yahoo.com>
16  */

17 public class IdentityHashMap extends HashMap JavaDoc
18 {
19     /**
20      * Constructor for IdentityHashMap.
21      * @param initialCapacity
22      * @param loadFactor
23      */

24     public IdentityHashMap(int initialCapacity, float loadFactor)
25     {
26         super(initialCapacity, loadFactor);
27     }
28
29     /**
30      * Constructor for IdentityHashMap.
31      * @param initialCapacity
32      */

33     public IdentityHashMap(int initialCapacity)
34     {
35         super(initialCapacity);
36     }
37
38     /**
39      * Constructor for IdentityHashMap.
40      */

41     public IdentityHashMap()
42     {
43         super();
44     }
45
46     /**
47      * Constructor for IdentityHashMap.
48      * @param t
49      */

50     public IdentityHashMap(Map JavaDoc t)
51     {
52         super(t);
53     }
54
55     /**
56      * @see Map#get(Object)
57      */

58     public Object JavaDoc get(Object JavaDoc key)
59     {
60         return super.get(new IDKey(key));
61     }
62
63     /**
64      * @see Map#put(Object, Object)
65      */

66     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value)
67     {
68         return super.put(new IDKey(key), value);
69     }
70
71     /**
72      * adds an object to the Map. new Identity(obj) is used as key
73      */

74     public Object JavaDoc add(Object JavaDoc value)
75     {
76         Object JavaDoc key = new IDKey(value);
77         if (! super.containsKey(key))
78         {
79             return super.put(key, value);
80         }
81         else return null;
82
83     }
84
85     /**
86      * @see Map#remove(Object)
87      */

88     public Object JavaDoc remove(Object JavaDoc key)
89     {
90         return super.remove(new IDKey(key));
91     }
92
93     /**
94      * @see Map#containsKey(Object)
95      */

96     public boolean containsKey(Object JavaDoc key)
97     {
98         return super.containsKey(new IDKey(key));
99     }
100 }
101
Popular Tags