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 @SuppressWarnings({"checkstyle:ClassTypeParameterName", "checkstyle:MethodTypeParameterName", "PMD.GenericsNaming"})
17 public final class NTuple2<T1 extends Comparable<T1>, T2 extends Comparable<T2>> implements Comparable<NTuple2<T1, T2>>
18 {
19
20
21
22
23
24
25
26
27 private final T1 object1;
28
29
30
31
32 private final T2 object2;
33
34
35
36
37
38
39
40
41 private NTuple2(final T1 obj1, final T2 obj2)
42 {
43 super();
44 Objects.requireNonNull(obj1, "obj1 is null");
45 Objects.requireNonNull(obj2, "obj2 is null");
46 this.object1 = obj1;
47 this.object2 = obj2;
48 }
49
50
51
52
53
54
55
56
57
58
59
60 public static <T1 extends Comparable<T1>, T2 extends Comparable<T2>> NTuple2<T1, T2> of(final T1 obj1, final T2 obj2)
61 {
62 return new NTuple2<>(obj1, obj2);
63 }
64
65
66
67
68
69
70
71
72 public T1 t1Value()
73 {
74 return this.object1;
75 }
76
77
78
79
80
81
82
83 public T2 t2Value()
84 {
85 return this.object2;
86 }
87
88
89
90
91
92
93
94
95 @Override
96 public int hashCode()
97 {
98 return Objects.hash(this.object1, this.object2);
99 }
100
101
102
103
104
105
106
107
108
109 @Override
110 public boolean equals(final Object obj)
111 {
112 if (this == obj)
113 {
114 return true;
115 }
116 if (!(obj instanceof NTuple2))
117 {
118 return false;
119 }
120 final NTuple2<T1, T2> other = (NTuple2<T1, T2>)obj;
121 boolean result = this.object1.equals(other.object1);
122 if (result)
123 {
124 result = this.object2.equals(other.object2);
125 }
126 return result;
127 }
128
129
130
131
132
133
134
135
136
137
138
139
140 @Override
141 public String toString()
142 {
143 final var builder = new StringBuilder(27);
144 builder.append("NTuple2[object1=").append(this.object1).append(", object2=").append(this.object2).append(']');
145 return builder.toString();
146 }
147
148
149
150
151
152
153
154
155
156 @Override
157 public int compareTo(final NTuple2<T1, T2> obj)
158 {
159 Objects.requireNonNull(obj, "obj");
160 int result = this.object1.compareTo(obj.object1);
161 if (result == 0)
162 {
163 result = this.object2.compareTo(obj.object2);
164 }
165 return result;
166 }
167
168 }