-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathTuple2.java
More file actions
67 lines (55 loc) · 1.67 KB
/
Tuple2.java
File metadata and controls
67 lines (55 loc) · 1.67 KB
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
package ssj.algorithm.lang;
/**
* Created by shenshijun on 15/2/14.
*/
final public class Tuple2<F, S> {
final private F first;
final private S second;
private Integer hash_code = null;
private String to_string = null;
public F getFirst() {
return first;
}
public S getSecond() {
return second;
}
@Override
public String toString() {
if (to_string == null) {
final StringBuilder sb = new StringBuilder("Tuple2{");
sb.append("first=").append(first);
sb.append(", second=").append(second);
sb.append('}');
to_string = sb.toString();
}
return to_string;
}
public static <F, S> Tuple2<F, S> empty() {
return new Tuple2<>(null, null);
}
public boolean isEmpty() {
return getFirst() == null && getSecond() == null;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Tuple2 tuple2 = (Tuple2) o;
if (first != null ? !first.equals(tuple2.first) : tuple2.first != null) return false;
if (second != null ? !second.equals(tuple2.second) : tuple2.second != null) return false;
return true;
}
@Override
public int hashCode() {
if (hash_code == null) {
int result = first != null ? first.hashCode() : 0;
result = 31 * result + (second != null ? second.hashCode() : 0);
hash_code = result;
}
return hash_code;
}
public Tuple2(F first, S second) {
this.first = first;
this.second = second;
}
}