1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Google, Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.internal.core.utils;
import com.google.common.base.Objects;
/**
* Pair of two objects.
*
* @author scheglov_ke
* @coverage core.util
*/
public final class Pair<L, R> {
private final L left;
private final R right;
////////////////////////////////////////////////////////////////////////////
//
// Constructor
//
////////////////////////////////////////////////////////////////////////////
public Pair(L left, R right) {
this.left = left;
this.right = right;
}
////////////////////////////////////////////////////////////////////////////
//
// Object
//
////////////////////////////////////////////////////////////////////////////
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof Pair<?, ?>)) {
return false;
}
Pair<?, ?> other = (Pair<?, ?>) o;
return Objects.equal(getLeft(), other.getLeft())
&& Objects.equal(getRight(), other.getRight());
}
@Override
public int hashCode() {
int hLeft = getLeft() == null ? 0 : getLeft().hashCode();
int hRight = getRight() == null ? 0 : getRight().hashCode();
return hLeft + 37 * hRight;
}
////////////////////////////////////////////////////////////////////////////
//
// Access
//
////////////////////////////////////////////////////////////////////////////
public L getLeft() {
return left;
}
public R getRight() {
return right;
}
////////////////////////////////////////////////////////////////////////////
//
// Factory
//
////////////////////////////////////////////////////////////////////////////
public static <L, R> Pair<L, R> create(L left, R right) {
return new Pair<L, R>(left, right);
}
}
|