Advertisement
Guest User

Pre handling in new Java version scheme

a guest
Jul 14th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. // When comparing two version strings, a string with a pre-release
  2. // identifier is always less than one with an equal $VNUM but no such
  3. // identifier. Pre-release identifiers are compared numerically when
  4. // they consist only of digits, and lexicographically otherwise.
  5. if(pre == null && other.pre != null) {
  6.   return 1;
  7. }
  8. if(pre != null && other.pre == null) {
  9.   return -1;
  10. }
  11. if(pre == null /* implicit && o.pre == null */) {
  12.   return 0;
  13. }
  14. // neither pre nor o.pre are null
  15. if(pre.equals(other.pre)) {
  16.   return 0;
  17. }
  18.  
  19. int value;
  20. try {
  21.   int thisPreAsInt = Integer.parseInt(pre);
  22.   int otherPreAsInt = Integer.parseInt(other.pre);
  23.   // compare numerically
  24.   value = thisPreAsInt - otherPreAsInt;
  25. }
  26. catch(NumberFormatException ex) {
  27.   // compare lexicographically
  28.   value = pre.compareTo(other.pre);
  29. }
  30. if(value < 0) {
  31.   return -1;
  32. }
  33. if(value > 0) {
  34.   return 1;
  35. }
  36.  
  37. return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement