78
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2008 Matthew Hall 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 * Matthew Hall - initial API and implementation (bug 215531)
|
|
10 ******************************************************************************/
|
|
11
|
|
12 module org.eclipse.jface.internal.databinding.viewers.ViewerElementWrapper;
|
|
13
|
|
14 import java.lang.all;
|
|
15
|
|
16 import org.eclipse.jface.viewers.IElementComparer;
|
|
17
|
|
18 /**
|
|
19 * A wrapper class for viewer elements, which uses an {@link IElementComparer}
|
|
20 * for computing {@link Object#equals(Object) equality} and
|
|
21 * {@link Object#hashCode() hashes}.
|
|
22 *
|
|
23 * @since 1.2
|
|
24 */
|
|
25 public class ViewerElementWrapper {
|
|
26 private final Object element;
|
|
27 private final IElementComparer comparer;
|
|
28
|
|
29 /**
|
|
30 * Constructs a ViewerElementWrapper wrapping the given element
|
|
31 *
|
|
32 * @param element
|
|
33 * the element being wrapped
|
|
34 * @param comparer
|
|
35 * the comparer to use for computing equality and hash codes.
|
|
36 */
|
|
37 public this(Object element, IElementComparer comparer) {
|
|
38 if (comparer is null)
|
|
39 throw new NullPointerException();
|
|
40 this.element = element;
|
|
41 this.comparer = comparer;
|
|
42 }
|
|
43
|
|
44 public bool equals(Object obj) {
|
|
45 if (!(null !is cast(ViewerElementWrapper)obj)) {
|
|
46 return false;
|
|
47 }
|
|
48 return comparer.equals(element, (cast(ViewerElementWrapper) obj).element);
|
|
49 }
|
|
50
|
|
51 public int hashCode() {
|
|
52 return comparer.hashCode(element);
|
|
53 }
|
|
54
|
|
55 Object unwrap() {
|
|
56 return element;
|
|
57 }
|
|
58 }
|