KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.axis.utils;
18
19 /**
20  * Wrap an identity key (System.identityHashCode())
21  */

22 public class IDKey {
23     private Object JavaDoc value = null;
24     private int id = 0;
25
26     /**
27      * Constructor for IDKey
28      * @param _value
29      */

30     public IDKey(Object JavaDoc _value) {
31         // This is the Object hashcode
32
id = System.identityHashCode(_value);
33         // There have been some cases (bug 11706) that return the
34
// same identity hash code for different objects. So
35
// the value is also added to disambiguate these cases.
36
value = _value;
37     }
38
39     /**
40      * returns hashcode
41      * @return
42      */

43     public int hashCode() {
44        return id;
45     }
46
47     /**
48      * checks if instances are equal
49      * @param other
50      * @return
51      */

52     public boolean equals(Object JavaDoc other) {
53         if (!(other instanceof IDKey)) {
54             return false;
55         }
56         IDKey idKey = (IDKey) other;
57         if (id != idKey.id) {
58             return false;
59         }
60         // Note that identity equals is used.
61
return value == idKey.value;
62     }
63 }
64
65
Popular Tags