KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > internal > databinding > internal > IdentityWrapper


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  ******************************************************************************/

11
12 package org.eclipse.jface.internal.databinding.internal;
13
14 /**
15  * Used for wrapping objects that define their own implementations of equals()
16  * and hashCode() when putting them in sets or hashmaps to ensure identity
17  * comparison.
18  *
19  * @since 1.0
20  *
21  */

22 public class IdentityWrapper {
23     final Object JavaDoc o;
24
25     public IdentityWrapper(Object JavaDoc o) {
26         this.o = o;
27     }
28     
29     public Object JavaDoc unwrap() {
30         return o;
31     }
32
33     public boolean equals(Object JavaDoc obj) {
34         if (obj.getClass() != IdentityWrapper.class) {
35             return false;
36         }
37         return o == ((IdentityWrapper) obj).o;
38     }
39
40     public int hashCode() {
41         return System.identityHashCode(o);
42     }
43 }
44
Popular Tags