KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > databinding > 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  * Daniel Kruegler - bug 137435
11  ******************************************************************************/

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

23 public class IdentityWrapper {
24     final Object JavaDoc o;
25
26     /**
27      * @param o
28      */

29     public IdentityWrapper(Object JavaDoc o) {
30         this.o = o;
31     }
32     
33     /**
34      * @return the unwrapped object
35      */

36     public Object JavaDoc unwrap() {
37         return o;
38     }
39
40     public boolean equals(Object JavaDoc obj) {
41         if (obj == null || obj.getClass() != IdentityWrapper.class) {
42             return false;
43         }
44         return o == ((IdentityWrapper) obj).o;
45     }
46
47     public int hashCode() {
48         return System.identityHashCode(o);
49     }
50 }
51
Popular Tags