KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the docs/licenses/apache-1.1.txt file.
7  */

8 package org.jboss.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  *
16  * @author Davanum Srinivas <dims@yahoo.com>
17  */

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

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

36    public IdentityHashMap(int initialCapacity)
37    {
38       super(initialCapacity);
39    }
40
41    /**
42     * Constructor for IdentityHashMap.
43     */

44    public IdentityHashMap()
45    {
46       super();
47    }
48
49    /**
50     * Constructor for IdentityHashMap.
51     *
52     * @param t
53     */

54    public IdentityHashMap(Map JavaDoc t)
55    {
56       super(t);
57    }
58
59    /**
60     * @see Map#get(Object)
61     */

62    public Object JavaDoc get(Object JavaDoc key)
63    {
64       return super.get(new IDKey(key));
65    }
66
67    /**
68     * @see Map#put(Object, Object)
69     */

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

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

93    public Object JavaDoc remove(Object JavaDoc key)
94    {
95       return super.remove(new IDKey(key));
96    }
97
98    /**
99     * @see Map#containsKey(Object)
100     */

101    public boolean containsKey(Object JavaDoc key)
102    {
103       return super.containsKey(new IDKey(key));
104    }
105 }
106
Popular Tags