-
Notifications
You must be signed in to change notification settings - Fork 2
/
Tuple3.java
112 lines (94 loc) · 2.25 KB
/
Tuple3.java
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
111
112
package de.tototec.utils.functional;
import java.io.Serializable;
/**
* Value class representing a 3-tuple.
*
* This class is immutable and thus thread-safe.
*
* @param <A>
* The type of the first element.
* @param <B>
* The type of the second element.
* @param <C>
* The type of the third element.
*/
public class Tuple3<A, B, C> implements Serializable {
private static final long serialVersionUID = 1L;
public static <A, B, C> Tuple3<A, B, C> of(final A a, final B b, final C c) {
return new Tuple3<A, B, C>(a, b, c);
}
public static <A, B, C> Tuple3<A, B, C> of(final Tuple2<A, B> ab, final C c) {
return new Tuple3<A, B, C>(ab.a(), ab.b(), c);
}
public static <A, B, C> Tuple3<A, B, C> of(final A a, final Tuple2<B, C> bc) {
return new Tuple3<A, B, C>(a, bc.a(), bc.b());
}
private final A a;
private final B b;
private final C c;
protected Tuple3(final A a, final B b, final C c) {
this.a = a;
this.b = b;
this.c = c;
}
public A a() {
return a;
}
public B b() {
return b;
}
public C c() {
return c;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((a() == null) ? 0 : a().hashCode());
result = prime * result + ((b() == null) ? 0 : b().hashCode());
result = prime * result + ((c() == null) ? 0 : c().hashCode());
return result;
}
@Override
public boolean equals(final Object other) {
if (this == other) {
return true;
}
if (!(other instanceof Tuple3)) {
return false;
}
final Tuple3<?, ?, ?> that = (Tuple3<?, ?, ?>) other;
if (!that.canEqual(this)) {
return false;
}
if (this.a() == null) {
if (that.a() != null) {
return false;
}
} else if (!this.a().equals(that.a())) {
return false;
}
if (this.b() == null) {
if (that.b() != null) {
return false;
}
} else if (!this.b().equals(that.b())) {
return false;
}
if (this.c() == null) {
if (that.c() != null) {
return false;
}
} else if (!this.c().equals(that.c())) {
return false;
}
return true;
}
public boolean canEqual(final Object other) {
return other instanceof Tuple3;
}
@Override
public String toString() {
return getClass().getSimpleName() + "(" + a() + "," + b() + "," + c() + ")";
}
}