Skip to content

Commit

Permalink
Merge pull request #8 from batmat/orEqual
Browse files Browse the repository at this point in the history
Add utility method when one also want equality to yield true
  • Loading branch information
batmat authored Jan 28, 2019
2 parents 55a68a5 + defe547 commit 7fc3da2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/hudson/util/VersionNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,14 @@ public boolean isNewerThan(VersionNumber rhs) {
return compareTo(rhs) > 0;
}

public boolean isOlderOrEqualTo(VersionNumber rhs) {
return compareTo(rhs) <= 0;
}

public boolean isNewerOrEqualTo(VersionNumber rhs) {
return compareTo(rhs) >= 0;
}

/**
* @deprecated see {@link #getDigitAt(int)}
*/
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/hudson/util/VersionNumberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,14 @@ public void testDigit() {
assertEquals(-1, new VersionNumber("").getDigitAt(-1));
assertEquals(-1, new VersionNumber("").getDigitAt(0));
}

public void testOrEqualTo() {
assertTrue(new VersionNumber("1.8").isNewerOrEqualTo(new VersionNumber("1.8")));
assertTrue(new VersionNumber("1.9").isNewerOrEqualTo(new VersionNumber("1.8")));
assertTrue(new VersionNumber("2").isNewerOrEqualTo(new VersionNumber("1.8")));

assertTrue(new VersionNumber("1.8").isOlderOrEqualTo(new VersionNumber("1.8")));
assertTrue(new VersionNumber("1.7").isOlderOrEqualTo(new VersionNumber("1.8")));
assertTrue(new VersionNumber("1").isOlderOrEqualTo(new VersionNumber("1.8")));
}
}

0 comments on commit 7fc3da2

Please sign in to comment.