@@ -24,18 +24,19 @@ public class Version implements Comparable<Version> {
2424 public final static Version V3_0_2 = new Version ("3.0.2" , 3 , 0 , 2 , null , true );
2525 public final static Version V3_0_3 = new Version ("3.0.3" , 3 , 0 , 3 , null , true );
2626 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 );
3536 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 )
3738 .collect (toMap (Version ::toString , Function .identity ()));
38- public final static Version LATEST = V3_1_7 ;
39+ public final static Version LATEST = V3_1_8 ;
3940
4041 private final String origString ;
4142 private final Integer major ;
@@ -167,10 +168,14 @@ public String getNormalizedString() {
167168 }
168169
169170 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 ) {
170175 if (i1 == null && i2 == null ) {
171176 return 0 ;
172177 } else if (i1 == null ) {
173- return -1 ;
178+ return nullMeansEqual ? 0 : -1 ;
174179 } else if (i2 == null ) {
175180 return 1 ;
176181 } else {
@@ -180,26 +185,30 @@ private int compareToWithNulls(@Nullable Integer i1, @Nullable Integer i2) {
180185
181186 @ Override
182187 public int compareTo (Version o ) {
188+ return compareTo (o , false );
189+ }
190+
191+ public int compareTo (Version o , boolean nullMeansEqual ) {
183192 int curResult ;
184193
185194 if (isValid () && o .isValid ()) {
186195
187- curResult = compareToWithNulls (getMajor (), o .getMajor ());
196+ curResult = compareToWithNulls (getMajor (), o .getMajor (), nullMeansEqual );
188197 if (curResult != 0 ) {
189198 return curResult ;
190199 }
191200
192- curResult = compareToWithNulls (getMinor (), o .getMinor ());
201+ curResult = compareToWithNulls (getMinor (), o .getMinor (), nullMeansEqual );
193202 if (curResult != 0 ) {
194203 return curResult ;
195204 }
196205
197- curResult = compareToWithNulls (getBugfix (), o .getBugfix ());
206+ curResult = compareToWithNulls (getBugfix (), o .getBugfix (), nullMeansEqual );
198207 if (curResult != 0 ) {
199208 return curResult ;
200209 }
201210
202- curResult = compareToWithNulls (getBuild (), o .getBuild ());
211+ curResult = compareToWithNulls (getBuild (), o .getBuild (), nullMeansEqual );
203212 if (curResult != 0 ) {
204213 return curResult ;
205214 }
@@ -220,6 +229,7 @@ private void versionsAreValid(Version v) throws InvalidVersionException {
220229
221230 /**
222231 * 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
223233 * Throws an InvalidVersionException if either this or the given version are invalid
224234 *
225235 * @param v Version to compare with
@@ -230,7 +240,7 @@ public boolean isGreaterOrEqualThan(Version v) throws InvalidVersionException {
230240
231241 versionsAreValid (v );
232242
233- return compareTo (v ) >= 0 ;
243+ return compareTo (v , true ) >= 0 ;
234244 }
235245
236246
@@ -240,11 +250,20 @@ public boolean isGreaterThan(Version v) throws InvalidVersionException {
240250 return compareTo (v ) > 0 ;
241251 }
242252
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+ */
243262 public boolean isLessOrEqualThan (Version v ) throws InvalidVersionException {
244263
245264 versionsAreValid (v );
246265
247- return compareTo (v ) <= 0 ;
266+ return compareTo (v , true ) <= 0 ;
248267 }
249268
250269 public boolean isLessThan (Version v ) throws InvalidVersionException {
0 commit comments