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 */
|
85
|
37 public this(String a, String b) {
|
|
38 this(stringcast(a), stringcast(b));
|
|
39 }
|
|
40 public this(Object a, String b) {
|
|
41 this(a, stringcast(b));
|
|
42 }
|
|
43 public this(String a, Object b) {
|
|
44 this(stringcast(a), b);
|
|
45 }
|
78
|
46 public this(Object a, Object b) {
|
|
47 this.a = a;
|
|
48 this.b = b;
|
|
49 }
|
|
50
|
85
|
51 public override hash_t toHash() {
|
78
|
52 final int prime = 31;
|
|
53 int result = 1;
|
85
|
54 result = prime * result + ((a is null) ? 0 : a.toHash());
|
|
55 result = prime * result + ((b is null) ? 0 : b.toHash());
|
78
|
56 return result;
|
|
57 }
|
|
58
|
85
|
59 public override equals_t opEquals(Object obj) {
|
78
|
60 if (this is obj)
|
|
61 return true;
|
|
62 if (obj is null)
|
|
63 return false;
|
85
|
64 if (this.classinfo !is obj.classinfo)
|
78
|
65 return false;
|
|
66 Pair other = cast(Pair) obj;
|
|
67 if (a is null) {
|
|
68 if (other.a !is null)
|
|
69 return false;
|
85
|
70 } else if (!a.opEquals(other.a))
|
78
|
71 return false;
|
|
72 if (b is null) {
|
|
73 if (other.b !is null)
|
|
74 return false;
|
85
|
75 } else if (!b.opEquals(other.b))
|
78
|
76 return false;
|
|
77 return true;
|
|
78 }
|
|
79
|
|
80 }
|