@@ -167,10 +167,14 @@ public String getNormalizedString() {
167167 }
168168
169169 private int compareToWithNulls (@ Nullable Integer i1 , @ Nullable Integer i2 ) {
170+ return compareToWithNulls (i1 , i2 , false );
171+ }
172+
173+ private int compareToWithNulls (@ Nullable Integer i1 , @ Nullable Integer i2 , boolean nullMeansEqual ) {
170174 if (i1 == null && i2 == null ) {
171175 return 0 ;
172176 } else if (i1 == null ) {
173- return -1 ;
177+ return nullMeansEqual ? 0 : -1 ;
174178 } else if (i2 == null ) {
175179 return 1 ;
176180 } else {
@@ -180,26 +184,30 @@ private int compareToWithNulls(@Nullable Integer i1, @Nullable Integer i2) {
180184
181185 @ Override
182186 public int compareTo (Version o ) {
187+ return compareTo (o , false );
188+ }
189+
190+ public int compareTo (Version o , boolean nullMeansEqual ) {
183191 int curResult ;
184192
185193 if (isValid () && o .isValid ()) {
186194
187- curResult = compareToWithNulls (getMajor (), o .getMajor ());
195+ curResult = compareToWithNulls (getMajor (), o .getMajor (), nullMeansEqual );
188196 if (curResult != 0 ) {
189197 return curResult ;
190198 }
191199
192- curResult = compareToWithNulls (getMinor (), o .getMinor ());
200+ curResult = compareToWithNulls (getMinor (), o .getMinor (), nullMeansEqual );
193201 if (curResult != 0 ) {
194202 return curResult ;
195203 }
196204
197- curResult = compareToWithNulls (getBugfix (), o .getBugfix ());
205+ curResult = compareToWithNulls (getBugfix (), o .getBugfix (), nullMeansEqual );
198206 if (curResult != 0 ) {
199207 return curResult ;
200208 }
201209
202- curResult = compareToWithNulls (getBuild (), o .getBuild ());
210+ curResult = compareToWithNulls (getBuild (), o .getBuild (), nullMeansEqual );
203211 if (curResult != 0 ) {
204212 return curResult ;
205213 }
@@ -220,6 +228,7 @@ private void versionsAreValid(Version v) throws InvalidVersionException {
220228
221229 /**
222230 * Compares this version to a given version and returns true if this version is greater or equal than the given one
231+ * 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
223232 * Throws an InvalidVersionException if either this or the given version are invalid
224233 *
225234 * @param v Version to compare with
@@ -230,7 +239,7 @@ public boolean isGreaterOrEqualThan(Version v) throws InvalidVersionException {
230239
231240 versionsAreValid (v );
232241
233- return compareTo (v ) >= 0 ;
242+ return compareTo (v , true ) >= 0 ;
234243 }
235244
236245
@@ -240,11 +249,20 @@ public boolean isGreaterThan(Version v) throws InvalidVersionException {
240249 return compareTo (v ) > 0 ;
241250 }
242251
252+ /**
253+ * Compares this version to a given version and returns true if this version is less or equal than the given one
254+ * 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
255+ * Throws an InvalidVersionException if either this or the given version are invalid
256+ *
257+ * @param v Version to compare with
258+ * @return
259+ * @throws InvalidVersionException
260+ */
243261 public boolean isLessOrEqualThan (Version v ) throws InvalidVersionException {
244262
245263 versionsAreValid (v );
246264
247- return compareTo (v ) <= 0 ;
265+ return compareTo (v , true ) <= 0 ;
248266 }
249267
250268 public boolean isLessThan (Version v ) throws InvalidVersionException {
0 commit comments