blob: c805ece46e26e00b0648cb2cd68e71c427df6fc0 (
plain) (
blame)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/*******************************************************************************
* Copyright (c) 2012, 2015 Ericsson
*
* 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:
* Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
* Mathieu Denis (mathieu.denis55@gmail.com) - Refactored code
* Bernd Hufmann - Integrated to TMF, fixed hashCode() and equals() methods
* Alexandre Montplaisir - Made non-null and immutable
*******************************************************************************/
package org.eclipse.tracecompass.tmf.core.util;
import org.eclipse.jdt.annotation.Nullable;
/**
* Pair utility class, encapsulates a pair of objects.
*
* @param <A>
* The type of the first object.
* @param <B>
* The type of the second object.
*
* @author Philippe Sawicki
*/
public class Pair<A, B> {
/**
* A reference to the first object.
*/
private final A fFirst;
/**
* A reference to the second object.
*/
private final B fSecond;
/**
* Constructor.
* @param first
* The pair's first object.
* @param second
* The pair's second object.
*/
public Pair(A first, B second) {
fFirst = first;
fSecond = second;
}
/**
* Returns a reference to the pair's first object.
*
* @return A reference to the pair's first object.
*/
public A getFirst() {
return fFirst;
}
/**
* Returns a reference to the pair's second object.
*
* @return A reference to the pair's second object.
*/
public B getSecond() {
return fSecond;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + fFirst.hashCode();
result = prime * result + fSecond.hashCode();
return result;
}
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Pair<?, ?> other = (Pair<?, ?>) obj;
if (!fFirst.equals(other.fFirst)) {
return false;
}
if (!fSecond.equals(other.fSecond)) {
return false;
}
return true;
}
@Override
public String toString() {
return "(" + fFirst + ", " + fSecond + ")"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
}
}
|