1
2
3
4 package de.powerstat.validation.containers;
5
6
7 import java.util.Objects;
8
9
10
11
12
13
14
15
16
17 @SuppressWarnings({"checkstyle:ClassTypeParameterName", "checkstyle:MethodTypeParameterName", "PMD.GenericsNaming"})
18 public final class NTuple3<T1 extends Comparable<T1>, T2 extends Comparable<T2>, T3 extends Comparable<T3>> implements Comparable<NTuple3<T1, T2, T3>>
19 {
20
21
22
23
24
25
26
27
28 private final T1 object1;
29
30
31
32
33 private final T2 object2;
34
35
36
37
38 private final T3 object3;
39
40
41
42
43
44
45
46
47
48 private NTuple3(final T1 obj1, final T2 obj2, final T3 obj3)
49 {
50 super();
51 Objects.requireNonNull(obj1, "obj1 is null");
52 Objects.requireNonNull(obj2, "obj2 is null");
53 Objects.requireNonNull(obj3, "obj3 is null");
54 this.object1 = obj1;
55 this.object2 = obj2;
56 this.object3 = obj3;
57 }
58
59
60
61
62
63
64
65
66
67
68
69
70
71 public static <T1 extends Comparable<T1>, T2 extends Comparable<T2>, T3 extends Comparable<T3>> NTuple3<T1, T2, T3> of(final T1 obj1, final T2 obj2, final T3 obj3)
72 {
73 return new NTuple3<>(obj1, obj2, obj3);
74 }
75
76
77
78
79
80
81
82
83 public T1 t1Value()
84 {
85 return this.object1;
86 }
87
88
89
90
91
92
93
94 public T2 t2Value()
95 {
96 return this.object2;
97 }
98
99
100
101
102
103
104
105 public T3 t3Value()
106 {
107 return this.object3;
108 }
109
110
111
112
113
114
115
116
117 @Override
118 public int hashCode()
119 {
120 return Objects.hash(this.object1, this.object2, this.object3);
121 }
122
123
124
125
126
127
128
129
130
131 @Override
132 public boolean equals(final Object obj)
133 {
134 if (this == obj)
135 {
136 return true;
137 }
138 if (!(obj instanceof NTuple3))
139 {
140 return false;
141 }
142 final NTuple3<T1, T2, T3> other = (NTuple3<T1, T2, T3>)obj;
143 boolean result = this.object1.equals(other.object1);
144 if (result)
145 {
146 result = this.object2.equals(other.object2);
147 if (result)
148 {
149 result = this.object3.equals(other.object3);
150 }
151 }
152 return result;
153 }
154
155
156
157
158
159
160
161
162
163
164
165
166 @Override
167 public String toString()
168 {
169 final var builder = new StringBuilder(37);
170 builder.append("NTuple3[object1=").append(this.object1).append(", object2=").append(this.object2).append(", object3=").append(this.object3).append(']');
171 return builder.toString();
172 }
173
174
175
176
177
178
179
180
181
182 @Override
183 public int compareTo(final NTuple3<T1, T2, T3> obj)
184 {
185 Objects.requireNonNull(obj, "obj");
186 int result = this.object1.compareTo(obj.object1);
187 if (result == 0)
188 {
189 result = this.object2.compareTo(obj.object2);
190 if (result == 0)
191 {
192 result = this.object3.compareTo(obj.object3);
193 }
194 }
195 return result;
196 }
197
198 }