private int compareVersions(String fullVersion1,String fullVersion2){
  Matcher v1Matcher=VERSION_PATTERN.matcher(fullVersion1);
  boolean isV1Match=v1Matcher.matches();
  Matcher v2Matcher=VERSION_PATTERN.matcher(fullVersion2);
  boolean isV2Match=v2Matcher.matches();
  if (isV1Match && !isV2Match) {
    return 1;
  }
 else   if (!isV1Match && isV2Match) {
    return -1;
  }
 else   if (!isV1Match && !isV2Match) {
    return 0;
  }
  String v1Major=v1Matcher.groupCount() >= 1 ? v1Matcher.group(1) : "0";
  String v1Minor=v1Matcher.groupCount() >= 2 ? v1Matcher.group(2) : "0";
  String v1Release=v1Matcher.groupCount() >= 3 ? v1Matcher.group(3) : "0";
  String v2Major=v2Matcher.groupCount() >= 1 ? v2Matcher.group(1) : "0";
  String v2Minor=v2Matcher.groupCount() >= 2 ? v2Matcher.group(2) : "0";
  String v2Release=v2Matcher.groupCount() >= 3 ? v2Matcher.group(3) : "0";
  int compareMajor=compareVersionParts(v1Major,v2Major);
  if (compareMajor == 1) {
    return 1;
  }
 else   if (compareMajor == -1) {
    return -1;
  }
 else {
    int compareMinor=compareVersionParts(v1Minor,v2Minor);
    if (compareMinor == 1) {
      return 1;
    }
 else     if (compareMinor == -1) {
      return -1;
    }
 else {
      int compareRelease=compareVersionParts(v1Release,v2Release);
      if (compareRelease == 1) {
        return 1;
      }
 else       if (compareRelease == -1) {
        return -1;
      }
 else {
        return 0;
      }
    }
  }
}

private int compareVersions ( String fullVersion1 , String fullVersion2 ) { Matcher v1Matcher = VERSION_PATTERN . matcher ( fullVersion1 ) ; boolean isV1Match = v1Matcher . matches ( ) ; Matcher v2Matcher = VERSION_PATTERN . matcher ( fullVersion2 ) ; boolean isV2Match = v2Matcher . matches ( ) ; if ( isV1Match && ! isV2Match ) { return 1 ; } else if ( ! isV1Match && isV2Match ) { return - 1 ; } else if ( ! isV1Match && ! isV2Match ) { return 0 ; } String v1Major = v1Matcher . groupCount ( ) >= 1 ? v1Matcher . group ( 1 ) : "0" ; String v1Minor = v1Matcher . groupCount ( ) >= 2 ? v1Matcher . group ( 2 ) : "0" ; String v1Release = v1Matcher . groupCount ( ) >= 3 ? v1Matcher . group ( 3 ) : "0" ; String v2Major = v2Matcher . groupCount ( ) >= 1 ? v2Matcher . group ( 1 ) : "0" ; String v2Minor = v2Matcher . groupCount ( ) >= 2 ? v2Matcher . group ( 2 ) : "0" ; String v2Release = v2Matcher . groupCount ( ) >= 3 ? v2Matcher . group ( 3 ) : "0" ; int compareMajor = compareVersionParts ( v1Major , v2Major ) ; if ( compareMajor == 1 ) { return 1 ; } else if ( compareMajor == - 1 ) { return - 1 ; } else { int compareMinor = compareVersionParts ( v1Minor , v2Minor ) ; if ( compareMinor == 1 ) { return 1 ; } else if ( compareMinor == - 1 ) { return - 1 ; } else { int compareRelease = compareVersionParts ( v1Release , v2Release ) ; if ( compareRelease == 1 ) { return 1 ; } else if ( compareRelease == - 1 ) { return - 1 ; } else { return 0 ; } } } }
compare two 3 - part version numbers and indicate whether version1 is equal to version2 , version1 is greater than version2 , version1 is less than version2 .
