KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > util > IdentityKey


1 package polyglot.util;
2
3 /**
4  * Class to be used for inserting objects in hashtables using pointer equality.
5  */

6 public class IdentityKey
7 {
8     Object JavaDoc obj;
9
10     public IdentityKey(Object JavaDoc obj) {
11         this.obj = obj;
12     }
13
14     public Object JavaDoc object() {
15         return obj;
16     }
17
18     public int hashCode() {
19         return System.identityHashCode(obj);
20     }
21
22     public boolean equals(Object JavaDoc other) {
23         return other instanceof IdentityKey
24             && ((IdentityKey) other).obj == obj;
25     }
26
27     public String JavaDoc toString() {
28         return "Id(" + obj + ")";
29     }
30 }
31
32
Popular Tags