Mercurial > projects > dwt2
comparison org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentityWrapper.d @ 78:0a55d2d5a946
Added file for databinding
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 14 Apr 2009 11:35:29 +0200 |
parents | |
children | 6be48cf9f95c |
comparison
equal
deleted
inserted
replaced
76:f05e6e8b2f2d | 78:0a55d2d5a946 |
---|---|
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 module org.eclipse.core.internal.databinding.IdentityWrapper; | |
14 | |
15 import java.lang.all; | |
16 | |
17 /** | |
18 * Used for wrapping objects that define their own implementations of equals() | |
19 * and hashCode() when putting them in sets or hashmaps to ensure identity | |
20 * comparison. | |
21 * | |
22 * @since 1.0 | |
23 * | |
24 */ | |
25 public class IdentityWrapper { | |
26 final Object o; | |
27 | |
28 /** | |
29 * @param o | |
30 */ | |
31 public this(Object o) { | |
32 this.o = o; | |
33 } | |
34 | |
35 /** | |
36 * @return the unwrapped object | |
37 */ | |
38 public Object unwrap() { | |
39 return o; | |
40 } | |
41 | |
42 public override bool opEquals(Object obj) { | |
43 if (obj is null || obj.getClass() !is IdentityWrapper.classinfo) { | |
44 return false; | |
45 } | |
46 return o is (cast(IdentityWrapper) obj).o; | |
47 } | |
48 | |
49 public int hashCode() { | |
50 return System.identityHashCode(o); | |
51 } | |
52 } |