/
Tuple3.java
192 lines (175 loc) · 4.57 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
* Copyright 2012-2024 CodeLibs Project and the Others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package org.codelibs.core.misc;
/**
* 3つの値の組です。
*
* @author koichik
* @param <T1>
* 1番目の値の型
* @param <T2>
* 2番目の値の型
* @param <T3>
* 3番目の値の型
*/
public class Tuple3<T1, T2, T3> {
/** 1番目の値 */
protected T1 value1;
/** 2番目の値 */
protected T2 value2;
/** 3番目の値 */
protected T3 value3;
/**
* 3つの値の組を作成して返します。
*
* @param <T1>
* 1番目の値の型
* @param <T2>
* 2番目の値の型
* @param <T3>
* 3番目の値の型
* @param value1
* 1番目の値
* @param value2
* 2番目の値
* @param value3
* 3番目の値
* @return 3つの値の組
*/
public static <T1, T2, T3> Tuple3<T1, T2, T3> tuple3(final T1 value1, final T2 value2, final T3 value3) {
return new Tuple3<>(value1, value2, value3);
}
/**
* インスタンスを構築します。
*/
public Tuple3() {
}
/**
* インスタンスを構築します。
*
* @param value1
* 1番目の値
* @param value2
* 2番目の値
* @param value3
* 3番目の値
*/
public Tuple3(final T1 value1, final T2 value2, final T3 value3) {
this.value1 = value1;
this.value2 = value2;
this.value3 = value3;
}
/**
* 1番目の値を返します。
*
* @return 1番目の値
*/
public T1 getValue1() {
return value1;
}
/**
* 1番目の値を設定します。
*
* @param value1
* 1番目の値
*/
public void setValue1(final T1 value1) {
this.value1 = value1;
}
/**
* 2番目の値を返します。
*
* @return 2番目の値
*/
public T2 getValue2() {
return value2;
}
/**
* 2番目の値を設定します。
*
* @param value2
* 2番目の値
*/
public void setValue2(final T2 value2) {
this.value2 = value2;
}
/**
* 3番目の値を返します。
*
* @return 3番目の値
*/
public T3 getValue3() {
return value3;
}
/**
* 3番目の値を設定します。
*
* @param value3
* 3番目の値
*/
public void setValue3(final T3 value3) {
this.value3 = value3;
}
@Override
public String toString() {
return "{" + value1 + ", " + value2 + ", " + value3 + "}";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((value1 == null) ? 0 : value1.hashCode());
result = prime * result + ((value2 == null) ? 0 : value2.hashCode());
result = prime * result + ((value3 == null) ? 0 : value3.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
@SuppressWarnings("unchecked")
final Tuple3<T1, T2, T3> other = (Tuple3<T1, T2, T3>) obj;
if (value1 == null) {
if (other.value1 != null) {
return false;
}
} else if (!value1.equals(other.value1)) {
return false;
}
if (value2 == null) {
if (other.value2 != null) {
return false;
}
} else if (!value2.equals(other.value2)) {
return false;
}
if (value3 == null) {
if (other.value3 != null) {
return false;
}
} else if (!value3.equals(other.value3)) {
return false;
}
return true;
}
}