78
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2005, 2008 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 module org.eclipse.core.internal.databinding.Pair;
|
|
12
|
|
13 import java.lang.all;
|
|
14
|
|
15 /**
|
|
16 * Class Pair. Represents a mathematical pair of objects (a, b).
|
|
17 * @since 1.0
|
|
18 */
|
|
19 public class Pair {
|
|
20
|
|
21 /**
|
|
22 * a in the pair (a, b)
|
|
23 */
|
|
24 public final Object a;
|
|
25
|
|
26 /**
|
|
27 * b in the pair (a, b)
|
|
28 */
|
|
29 public final Object b;
|
|
30
|
|
31 /**
|
|
32 * Construct a Pair(a, b)
|
|
33 *
|
|
34 * @param a a in the pair (a, b)
|
|
35 * @param b b in the pair (a, b)
|
|
36 */
|
|
37 public this(Object a, Object b) {
|
|
38 this.a = a;
|
|
39 this.b = b;
|
|
40 }
|
|
41
|
|
42 public int hashCode() {
|
|
43 final int prime = 31;
|
|
44 int result = 1;
|
|
45 result = prime * result + ((a is null) ? 0 : a.hashCode());
|
|
46 result = prime * result + ((b is null) ? 0 : b.hashCode());
|
|
47 return result;
|
|
48 }
|
|
49
|
|
50 public override bool opEquals(Object obj) {
|
|
51 if (this is obj)
|
|
52 return true;
|
|
53 if (obj is null)
|
|
54 return false;
|
|
55 if (getClass() !is obj.getClass())
|
|
56 return false;
|
|
57 Pair other = cast(Pair) obj;
|
|
58 if (a is null) {
|
|
59 if (other.a !is null)
|
|
60 return false;
|
|
61 } else if (!a.equals(other.a))
|
|
62 return false;
|
|
63 if (b is null) {
|
|
64 if (other.b !is null)
|
|
65 return false;
|
|
66 } else if (!b.equals(other.b))
|
|
67 return false;
|
|
68 return true;
|
|
69 }
|
|
70
|
|
71 }
|