Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // When comparing two version strings, a string with a pre-release
- // identifier is always less than one with an equal $VNUM but no such
- // identifier. Pre-release identifiers are compared numerically when
- // they consist only of digits, and lexicographically otherwise.
- if(pre == null && other.pre != null) {
- return 1;
- }
- if(pre != null && other.pre == null) {
- return -1;
- }
- if(pre == null /* implicit && o.pre == null */) {
- return 0;
- }
- // neither pre nor o.pre are null
- if(pre.equals(other.pre)) {
- return 0;
- }
- int value;
- try {
- int thisPreAsInt = Integer.parseInt(pre);
- int otherPreAsInt = Integer.parseInt(other.pre);
- // compare numerically
- value = thisPreAsInt - otherPreAsInt;
- }
- catch(NumberFormatException ex) {
- // compare lexicographically
- value = pre.compareTo(other.pre);
- }
- if(value < 0) {
- return -1;
- }
- if(value > 0) {
- return 1;
- }
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement