-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPair.java
More file actions
46 lines (38 loc) · 937 Bytes
/
Pair.java
File metadata and controls
46 lines (38 loc) · 937 Bytes
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
package cs2030.util;
public class Pair<T, U> {
private final T t;
private final U u;
private Pair(T t, U u) {
this.t = t;
this.u = u;
}
public static <T, U> Pair<T, U> of(T t, U u) {
return new Pair<T, U>(t, u);
}
public T first() {
return this.t;
}
public U second() {
return this.u;
}
@Override
public String toString() {
return "(" + this.t + ", " + this.u + ")";
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (obj instanceof Pair) {
Pair<?,?> other = (Pair<?,?>) obj;
return this.first().equals(other.first()) &&
this.second().equals(other.second());
} else {
return false;
}
}
@Override
public int hashCode() {
return java.util.Objects.hash(t, u);
}
}