@@ -24,18 +24,19 @@ public class Version implements Comparable<Version> {
24
24
public final static Version V3_0_2 = new Version ("3.0.2" , 3 , 0 , 2 , null , true );
25
25
public final static Version V3_0_3 = new Version ("3.0.3" , 3 , 0 , 3 , null , true );
26
26
public final static Version V3_0_4 = new Version ("3.0.4" , 3 , 0 , 4 , null , true );
27
- public final static Version V3_1_0 = new Version ("3.1.0" , 3 , 1 , 0 , null , true );
28
- public final static Version V3_1_1 = new Version ("3.1.1" , 3 , 1 , 1 , null , true );
29
- public final static Version V3_1_2 = new Version ("3.1.2" , 3 , 1 , 2 , null , true );
30
- public final static Version V3_1_3 = new Version ("3.1.3" , 3 , 1 , 3 , null , true );
31
- public final static Version V3_1_4 = new Version ("3.1.4" , 3 , 1 , 4 , null , true );
32
- public final static Version V3_1_5 = new Version ("3.1.5" , 3 , 1 , 5 , null , true );
33
- public final static Version V3_1_6 = new Version ("3.1.6" , 3 , 1 , 6 , null , true );
34
- public final static Version V3_1_7 = new Version ("3.1.7" , 3 , 1 , 7 , null , true );
27
+ public final static Version V3_1_0 = new Version ("3.1.0" , 3 , 1 , 0 , 1847 , true );
28
+ public final static Version V3_1_1 = new Version ("3.1.1" , 3 , 1 , 1 , 1865 , true );
29
+ public final static Version V3_1_2 = new Version ("3.1.2" , 3 , 1 , 2 , 2130 , true );
30
+ public final static Version V3_1_3 = new Version ("3.1.3" , 3 , 1 , 3 , 2398 , true );
31
+ public final static Version V3_1_4 = new Version ("3.1.4" , 3 , 1 , 4 , 2223 , true );
32
+ public final static Version V3_1_5 = new Version ("3.1.5" , 3 , 1 , 5 , 2707 , true );
33
+ public final static Version V3_1_6 = new Version ("3.1.6" , 3 , 1 , 6 , 2729 , true );
34
+ public final static Version V3_1_7 = new Version ("3.1.7" , 3 , 1 , 7 , 3085 , true );
35
+ public final static Version V3_1_8 = new Version ("3.1.8" , 3 , 1 , 8 , 3188 , true );
35
36
private final static Map <String , Version > knownVersions =
36
- Stream .of (V3_0_0 , V3_0_1 , V3_0_2 , V3_0_3 , V3_0_4 , V3_1_0 , V3_1_1 , V3_1_2 , V3_1_3 , V3_1_4 , V3_1_5 , V3_1_6 , V3_1_7 )
37
+ Stream .of (V3_0_0 , V3_0_1 , V3_0_2 , V3_0_3 , V3_0_4 , V3_1_0 , V3_1_1 , V3_1_2 , V3_1_3 , V3_1_4 , V3_1_5 , V3_1_6 , V3_1_7 , V3_1_8 )
37
38
.collect (toMap (Version ::toString , Function .identity ()));
38
- public final static Version LATEST = V3_1_7 ;
39
+ public final static Version LATEST = V3_1_8 ;
39
40
40
41
private final String origString ;
41
42
private final Integer major ;
@@ -167,10 +168,14 @@ public String getNormalizedString() {
167
168
}
168
169
169
170
private int compareToWithNulls (@ Nullable Integer i1 , @ Nullable Integer i2 ) {
171
+ return compareToWithNulls (i1 , i2 , false );
172
+ }
173
+
174
+ private int compareToWithNulls (@ Nullable Integer i1 , @ Nullable Integer i2 , boolean nullMeansEqual ) {
170
175
if (i1 == null && i2 == null ) {
171
176
return 0 ;
172
177
} else if (i1 == null ) {
173
- return -1 ;
178
+ return nullMeansEqual ? 0 : -1 ;
174
179
} else if (i2 == null ) {
175
180
return 1 ;
176
181
} else {
@@ -180,26 +185,30 @@ private int compareToWithNulls(@Nullable Integer i1, @Nullable Integer i2) {
180
185
181
186
@ Override
182
187
public int compareTo (Version o ) {
188
+ return compareTo (o , false );
189
+ }
190
+
191
+ public int compareTo (Version o , boolean nullMeansEqual ) {
183
192
int curResult ;
184
193
185
194
if (isValid () && o .isValid ()) {
186
195
187
- curResult = compareToWithNulls (getMajor (), o .getMajor ());
196
+ curResult = compareToWithNulls (getMajor (), o .getMajor (), nullMeansEqual );
188
197
if (curResult != 0 ) {
189
198
return curResult ;
190
199
}
191
200
192
- curResult = compareToWithNulls (getMinor (), o .getMinor ());
201
+ curResult = compareToWithNulls (getMinor (), o .getMinor (), nullMeansEqual );
193
202
if (curResult != 0 ) {
194
203
return curResult ;
195
204
}
196
205
197
- curResult = compareToWithNulls (getBugfix (), o .getBugfix ());
206
+ curResult = compareToWithNulls (getBugfix (), o .getBugfix (), nullMeansEqual );
198
207
if (curResult != 0 ) {
199
208
return curResult ;
200
209
}
201
210
202
- curResult = compareToWithNulls (getBuild (), o .getBuild ());
211
+ curResult = compareToWithNulls (getBuild (), o .getBuild (), nullMeansEqual );
203
212
if (curResult != 0 ) {
204
213
return curResult ;
205
214
}
@@ -220,6 +229,7 @@ private void versionsAreValid(Version v) throws InvalidVersionException {
220
229
221
230
/**
222
231
* Compares this version to a given version and returns true if this version is greater or equal than the given one
232
+ * If one of the version parts of the base version is null, this level is assumed equal no matter the comparing level's version part
223
233
* Throws an InvalidVersionException if either this or the given version are invalid
224
234
*
225
235
* @param v Version to compare with
@@ -230,7 +240,7 @@ public boolean isGreaterOrEqualThan(Version v) throws InvalidVersionException {
230
240
231
241
versionsAreValid (v );
232
242
233
- return compareTo (v ) >= 0 ;
243
+ return compareTo (v , true ) >= 0 ;
234
244
}
235
245
236
246
@@ -240,11 +250,20 @@ public boolean isGreaterThan(Version v) throws InvalidVersionException {
240
250
return compareTo (v ) > 0 ;
241
251
}
242
252
253
+ /**
254
+ * Compares this version to a given version and returns true if this version is less or equal than the given one
255
+ * If one of the version parts of the base version is null, this level is assumed equal no matter the comparing level's version part
256
+ * Throws an InvalidVersionException if either this or the given version are invalid
257
+ *
258
+ * @param v Version to compare with
259
+ * @return
260
+ * @throws InvalidVersionException
261
+ */
243
262
public boolean isLessOrEqualThan (Version v ) throws InvalidVersionException {
244
263
245
264
versionsAreValid (v );
246
265
247
- return compareTo (v ) <= 0 ;
266
+ return compareTo (v , true ) <= 0 ;
248
267
}
249
268
250
269
public boolean isLessThan (Version v ) throws InvalidVersionException {
0 commit comments